Table of Contents
Objective: Create a Sphinx container from a project on GitHub without modifications.
It is helpful to start with a project that we know works before making modifications. We will use a project from GitHub called dldl/sphinx-server. GitHub is a repository for open-source projects.
We will use port 20852 for this project.
First, we will clone the dldl/sphinx-server project.
Cloning a GitHub project using Ubuntu 18.04 is easy! You use the command
git clonewith the site to clone as the argument.
Go to the dldl/sphinx-server project page
Copy the project clone URL
Clone the project using
git clone <project-url.git>
Change to the root directory using
cd ~or change to the directory of your choice before cloning the project
This will create a folder called sphinx-server
cd ~ git clone https://github.com/dldl/sphinx-server.git cd sphinx-server
root@vps298933:~# cd ~ root@vps298933:~# git clone https://github.com/dldl/sphinx-server.git Cloning into 'sphinx-server'... remote: Enumerating objects: 242, done. remote: Total 242 (delta 0), reused 0 (delta 0), pack-reused 242 Receiving objects: 100% (242/242), 38.09 KiB | 443.00 KiB/s, done. Resolving deltas: 100% (127/127), done. root@vps298933:~# cd sphinx-server root@vps298933:~/sphinx-server# root@vps298933:~/sphinx-server# ls -lh total 16K -rw-r--r-- 1 root root 739 Apr 4 10:34 Dockerfile -rw-r--r-- 1 root root 1.1K Apr 4 10:34 LICENCE -rw-r--r-- 1 root root 2.9K Apr 4 10:34 README.md -rw-r--r-- 1 root root 3.5K Apr 4 10:34 server.py root@vps298933:~/sphinx-server#
Now, let’s start the project using default parameters from the project instructions.
From dldl/sphinx-server, Copy and paste the docker run command in section With autobuild enabled
Change the port to an open port on the VPS. Let’s use 20852
Verify the container is running using
curl --head localhost:20852to verify the container is responding to HTTP requests.
curl will respond with error
HTTP/1.1 404 Not Found
However, we know the server is working based on the HTTP request (
docker run -itd -v "$(pwd)":/web -u $(id -u):$(id -g) -p 20852:8000 --name sphinx-server dldl/sphinx-server docker ps curl --head localhost:20852
Here are the
itruns the container with an interactive shell.
dstarts the container in daemon mode (runs in the background).
Defines a volume (
/web) to mount in the current directory.
$(pwd)command returns the current directory, the location where the user executes
/webis the directory in the container to mount on the VPS. This directory contains the config file and web documents.
It will mount the directory on the localhost (VPS) at ~/sphinx-server/web
-u $(id -u):$(id -g)
Sets the user and user ID ofthe container to match that of the current user.
Opens port 20852 on the VPS and directs that traffic to port 8000 on the container.
20852: External port (in VPS)
8000: Internal port (in container)
Sets the name of the container
The name of the container to run.
Docker looks for this container locally, on the VPS.
It downloads the container from Docker Hub if it does not reside on the VPS
root@vps298933:~/sphinx-server# docker run -itd -v "$(pwd)":/web -u $(id -u):$(id -g) -p 20852:8000 --name sphinx-server dldl/sphinx-server 5fd156bd14131f0bb2e17b23f8901cc97de1f6fa6c689a7a283757f7e7cae2f8 root@vps298933:~/sphinx-server# root@vps298933:~/sphinx-server# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5fd156bd1413 dldl/sphinx-server "python /opt/sphinx-…" 4 seconds ago Up 2 seconds 8093/tcp, 35729/tcp, 0.0.0.0:20852->8000/tcp sphinx-server 76cbf38e5975 nextcloud "/entrypoint.sh apac…" 4 days ago Up 19 hours 0.0.0.0:20850->80/tcp nextclouddocker_app_1 2906aaa944f5 mariadb "docker-entrypoint.s…" 4 days ago Up 19 hours 3306/tcp nextclouddocker_db_1 8f5b05b6c627 redis "docker-entrypoint.s…" 4 days ago Up 19 hours 6379/tcp nextclouddocker_redis_1 c60b6e70e4a9 wordpress:latest "docker-entrypoint.s…" 4 days ago Up 19 hours 0.0.0.0:20851->80/tcp wordpressdocker_wordpress_1 386e4587b991 mariadb "docker-entrypoint.s…" 4 days ago Up 19 hours 3306/tcp wordpressdocker_db_1 913ff74dd94c redis "docker-entrypoint.s…" 4 days ago Up 19 hours 6379/tcp wordpressdocker_redis_1 root@vps298933:~/sphinx-server# curl --head localhost:20852 HTTP/1.1 404 Not Found Date: Thu, 04 Apr 2019 05:37:21 GMT Content-Length: 69 Content-Type: text/html; charset=UTF-8 Server: TornadoServer/5.1.1 root@vps298933:~/sphinx-server#
docker-compose.ymlhave the same end result. Chose the methods that works for you.
We can use
docker runif we won’t have many arguments.
You have to remember the specific
docker runarguments when you remove and restart the container.
We can build a
docker-composestores the data in a file.
It takes more time to write, but the configuration is stored for easy modification or restarting.
Getting Started with Sphinx informs us of the setup procedure. We have to
sphinx-quickstart and then
make html. We need to run both of
these commands in the container.
Fist, open a shell into the container using the name of the container.
docker exec -it sphinx-server /bin/sh
docker execallows us to execute a command on a container. Let’s look at this command before moving on.
docker exec -it <container> <command>
-iruns the container in interactive mode that can accept user input.
-tcreates a terminal inside of the container.
containerto execute the command in.
commandto execute, such as staring the
Then, run the init program
Use the default option for most choices. Press Enter.
Separate source and build directories (y/n) [n]:
Name prefix for templates and static dir [_]:
Project name: Enter a name
Author name(s): Enter a name
Project release :
Project language [en]: Press Enter or ru
Source file suffix [.rst]:
Name of your master document (without suffix) [index]:
autodoc: automatically insert docstrings from modules (y/n) [n]: y
doctest: automatically test code snippets in doctest blocks (y/n) [n]:
intersphinx: link between Sphinx documentation of different projects (y/n) [n]:
todo: write “todo” entries that can be shown or hidden on build (y/n) [n]:
coverage: checks for documentation coverage (y/n) [n]:
imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
mathjax: include math, rendered in the browser by MathJax (y/n) [n]:
ifconfig: conditional inclusion of content based on config values (y/n) [n]:
viewcode: include links to the source code of documented Python objects (y/n) [n]:
githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:
Create Makefile? (y/n) [y]:
Create Windows command file? (y/n) [y]: Press Enter or n
root@vps298933:~# docker exec -it sphinx-server /bin/sh /web # /web # sphinx-quickstart Welcome to the Sphinx 1.8.5 quickstart utility. Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets). Selected root path: . You have two options for placing the build directory for Sphinx output. Either, you use a directory "_build" within the root path, or you separate "source" and "build" directories within the root path. > Separate source and build directories (y/n) [n]: Inside the root directory, two more directories will be created; "_templates" for custom HTML templates and "_static" for custom stylesheets and other static files. You can enter another prefix (such as ".") to replace the underscore. > Name prefix for templates and static dir [_]: The project name will occur in several places in the built documentation. > Project name: Test Sphinx Project > Author name(s): * Please enter some text. > Author name(s): jj8i.cc > Project release : If the documents are to be written in a language other than English, you can select a language here by its language code. Sphinx will then translate text that it generates into that language. For a list of supported codes, see http://sphinx-doc.org/config.html#confval-language. > Project language [en]: ru The file name suffix for source files. Commonly, this is either ".txt" or ".rst". Only files with this suffix are considered documents. > Source file suffix [.rst]: One document is special in that it is considered the top node of the "contents tree", that is, it is the root of the hierarchical structure of the documents. Normally, this is "index", but if your "index" document is a custom template, you can also set this to another filename. > Name of your master document (without suffix) [index]: Indicate which of the following Sphinx extensions should be enabled: > autodoc: automatically insert docstrings from modules (y/n) [n]: y > doctest: automatically test code snippets in doctest blocks (y/n) [n]: > intersphinx: link between Sphinx documentation of different projects (y/n) [n]: > todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: > coverage: checks for documentation coverage (y/n) [n]: > imgmath: include math, rendered as PNG or SVG images (y/n) [n]: > mathjax: include math, rendered in the browser by MathJax (y/n) [n]: > ifconfig: conditional inclusion of content based on config values (y/n) [n]: > viewcode: include links to the source code of documented Python objects (y/n) [n]: > githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: A Makefile and a Windows command file can be generated for you so that you only have to run e.g. 'make html' instead of invoking sphinx-build directly. > Create Makefile? (y/n) [y]: > Create Windows command file? (y/n) [y]: Creating file ./conf.py. Creating file ./index.rst. Creating file ./Makefile. Creating file ./make.bat. Finished: An initial directory structure has been created. You should now populate your master file ./index.rst and create other documentation source files. Use the Makefile to build the docs, like so: make builder where "builder" is one of the supported builders, e.g. html, latex or linkcheck. /web #
conf.pycontains the configuration for Sphinx. The file was created after running
make htmlto build the project
/web # make html Running Sphinx v1.8.5 loading translations [ru]... done building [mo]: targets for 0 po files that are out of date building [html]: targets for 1 source files that are out of date updating environment: 1 added, 0 changed, 0 removed reading sources... [100%] index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] index generating indices... genindex writing additional pages... search copying static files... done copying extra files... done dumping search index in Russian (code: ru) ... done dumping object inventory... done build succeeded. The HTML pages are in _build/html. /web #
Exit the shell and then verify that the Sphinx server is working using
We should see an
HTTP/1.1 200 OKcode
curl --head localhost:20852 curl localhost:20852
root@vps298933:~# curl --head localhost:20852 HTTP/1.1 200 OK Content-Length: 3848 Accept-Ranges: bytes Server: TornadoServer/5.1.1 Last-Modified: Fri, 05 Apr 2019 10:24:27 GMT Etag: "4548821785384f4640015849281549fd" Date: Fri, 05 Apr 2019 10:27:10 GMT Content-Type: text/html root@vps298933:~# curl localhost:20852 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ru"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome to Test Sphinx Project’s documentation! — Документация Test Sphinx Project </title>
The default Sphinx theme is alabaster. We want to use Read the Docs Theme. The installation guide describes the change that we need to make to the config file.
If you want to preview the alabaster theme, configure the reverse proxy, then enable the Read the Docs theme.
Edit the Sphinx config file:
html_theme = 'alabaster'on line 78
Comment out that line using the
Add Read the Docs theme:
html_theme = 'sphinx_rtd_theme'
73 74 75 76 77 78 79 80 81 82
# -- Options for HTML output------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # #html_theme = 'alabaster' html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the