Odoo 12 Development Essentials
上QQ阅读APP看书,第一时间看更新

Installing Odoo using Docker containers

Docker provides a convenient multi-platform solution to run applications. It can be used to run applications on macOS, Linux, and Windows. The container technology is simple to use and resource-efficient when compared to classic virtual machines.

You must first have Docker installed in your system. The Docker CE is free of charge, and can be downloaded from https://www.docker.com. It's worth referring to Docker's website for the latest installation details.

In particular, keep in mind that virtualization must be enabled in your BIOS setup. Also, the Docker CE for Windows requires Hyper-V, only available in Windows 10 Enterprise or Education releases (see https://docs.docker.com/docker-for-windows/install), and Docker CE for mac requires OS X El Capitan 10.11 and newer macOS releases.

For other Windows and macOS versions, you should instead install Docker Toolbox, available at https://docs.docker.com/toolbox/overview. Docker Toolbox bundles VirtualBox and provides a preconfigured shell that should be used as the command-line environment to operate Docker containers.

The Odoo Docker images are available in the Docker store at https://store.docker.com/images/odoo. There, we can find the versions available, and the basic instructions to get started with them. To run Odoo, we will need two Docker containers, one for the PostgreSQL database, and another for the Odoo server.

The installation and operation is done from a command-line window. To install the PostgreSQL Docker container, run this:

$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres:10

It will download the latest PostgreSQL image from the internet, and start a container for it running as a background job.

Next, install and run the Odoo server container, linking it to the PostgreSQL container we just started, and exposing it on port 8069:

$ docker run -t -p 8069:8069 --name odoo --link db:db odoo:12.0 -d odoo12

With this, you will see the live Odoo server log in your terminal window, and can access the Odoo instance by opening http://localhost:8069 with your favorite web browser.

The Odoo server can fail to start if port  8069 is already in use, for example, by an already running Odoo server. In this case, you might look for and stop the running service (for example, by looking at the list of running services), or try to start this Odoo server on a different port by changing the -p option. For example, to use port 8070, use  -p 8070:8069 . In that case, you probably also  want to change -d <dbname> to set the database name that instance should use.

There are a few basic commands you should know to help manage these Docker containers:

  • docker stop <name> stops a container
  • docker start <name> starts a container
  • docker start -a <name> starts a container, and attaches the output, such as the server log, to the terminal window
  • docker attach <name> reattaches a container's output to the current terminal window
  • docker ps lists the current Docker containers

These are the basic commands needed to operate our Docker containers.

In case you get in trouble running the containers, here is a recipe to start over:

$ docker container stop db
$ docker container rm db
$ docker container stop odoo
$ docker container rm odoo

The Docker technology has more potential, and it might be interesting to learn more about it. The Docker website has good learning documentation. A good place to get started is https://www.docker.com/get-started.