How it works…

Docker allows you to create system images and then ship them around to run them on other servers. Docker images are created by writing a Dockerfile, which describes how to add layers generally to a pre-existing Dockerfile. In our case, we start with a Debian stable image (in the FROM line from the file). After adding some descriptive LABEL, we configure the ENTRYPOINT and command (CMD) of the image, which will be run when we start the container. The ENV section provides some configuration settings which will be used by the entry point script to run Odoo the way we want. The VOLUME line is used to provision a place where persistent data will be stored. This is important because Docker containers are essentially transient, and all the data inside a container will be lost when the container is stopped, unless it is placed in a Docker volume.

Then, the Dockerfile has a number of RUN commands that are the instructions for actually building the environment: we install buildtime and runtime dependencies, and uninstall the buildtime dependencies. Finally, we COPY the contents of the current directory to the container. The .dockerignore file is used to avoid copying unnecessary files.

With the Dockerfile ready, we can now build the image. The docker build command takes two parameters : the name of the image and a path to the directory. The name of the images are normally formed as companyname/projectname, but you may use just projectname for testing.

We use the docker save command to produce a tarball dump of the image in order to ship it later to the production server, where the docker load command can be used to load it back into the Docker environment.

At this point, we could run our instance using a local PostgreSQL installation, by configuring PostgreSQL to listen on all network interfaces, and running:

docker run -e ODOO_DB_HOST=db_server_name  
yourcompany/yourproject

However, to get a feel of the benefits of Docker, we build a docker composition by writing a docker-compose.yml file. A Docker composition describes several Docker containers which are going to work together in a private virtual network. In our case, we will add a second container to run the PostgreSQL. Inside the docker-compose.yml file, we list the containers we will use, and specify their configuration: the environment variables values we are setting (overriding the ones from the images), the dependencies between the containers... Then, from a directory that contains the composition file, we can use the docker-compose command to control the stack:

$ docker-compose up -d   # start the stack as a daemon
$ docker compose logs -f odoo # monitor the output
# odoo container
$ docker compose down # stop the stack
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.75.133