Quickstart to Working with Docker and Odoo by: Holden Rehg

Quickstart to Working with Docker and Odoo by: Holden Rehg

   I’ve been asked a handful of times about my Dockerized Odoo article. Even today, eight years after the release of Docker, there’s hesitation around developing with it. I completely understand that because Docker can be complex.

Originally I wanted to cover the major topics, features, and pain points that I noticed as a developer working with Docker. That’s where the Dockerized Odoo article came from. Now I think I can help a certain type of developer by putting out a quick start guide with simpler steps. This is targeted towards that developer who might not need every detail.

So that’s what I’m aiming to do here. Here’s the most pragmatic quickstart guide to working with Odoo and Docker that I can come up with:

 

Installing Docker

For detailed instructions on getting set up in a specific environment, take a look at docs.docker.com/get-docker/. At the end of the day, we need access to the docker command-line tool. This is what we’ll use to work with, control, and manipulate our containers.

Linux/Unix

Using Docker’s docker-install script is the easiest way to install Docker on Linux.

Mac

On a Mac, you need to download the Docker Desktop .dmg to install the application from docs.docker.com/docker-for-mac/install/.

Windows

Now, to be honest, I have very little experience with Docker on Windows, but I have set it up a handful of times. Using docs.docker.com/docker-for-windows/install/ and downloading the Docker Desktop application was pretty straightforward.

I would make sure you have access to docker from PowerShell once it’s installed.

 

Local Development

As Odoo developers, there is a handful of tasks that we do over and over and over while building Odoo modules or applications. I’m going to show you how to handle the basic tasks to get your work done day to day.

For this section, we are just going to stick with standard docker commands.

Starting an Odoo Instance

 

 

When starting a brand new instance, there are two steps:

  1. Startup a Postgres database container. Use a name unique to your project. For example, you’ll see below that I am using myodoo_db since I am working on a sample project called myodoo.


 

  1. Startup the Odoo container. Similarly, try to use a unique name. I’m again prefixing the name with myodoo_ to keep the container names unique.

In this example, we’ve opened up the Odoo instance to http://localhost:8069.

 

Stopping an Odoo Instance

Containers can either be run in the foreground or background. So far, we are running the Postgres container in the background (using the -d flag) and the Odoo instance in the foreground.

To stop the Odoo container, you can just use ctrl+c.

To stop a container from running in the background, you can use docker stop {container-name}. It’s helpful first to run docker ps to see what’s running right now.

 

Restarting an Odoo Instance

To bring containers back up that are currently off, use docker start.

Or, to restart containers that are already running, use docker restart. For example, when coding a new module, you’ll probably use docker restart often.

 

Configuring Odoo

The configurations for the Odoo instance can be set by either passing an inline argument or providing a new Odoo.conf file.

It’s important to keep in mind that certain parts of containers cannot be modified once they are created. They are meant to be easily destroyed and recreated. So first, we need to get rid of our original Odoo container:

 

 

To create a new container with inline arguments, it’s possible to pass them in via the keyword:

To create a new container with a new conf file all together we are going to use the -v, which defines a new volume. A volume is essentially a way to share data between your host computer and the container. In this example, it’s assuming that you have a file called /my/odoo/odoo.conf on your computer.

 

Adding Custom Add-Ons

Now we may want to load in some of our own modules that we’re working on. I have a sample directory under /odoo/myodoo for this sample project, and it looks like this:

To mount these add-ons into the Odoo container, we need to link a volume to a designated directory that the Odoo container has built-in for extra add-ons at /mnt/extra_addons:

 

 

Once started up, you will have access to your add-ons via the Apps menu as usual. As you’re developing your add-ons, you can docker restart myodoo_odoo to reload your python code.

Connecting to the Database

Running any command “inside” of the container can be done via docker exec. This is also helpful to access the database. When first creating the database container, we passed in environment variables for the credentials (user is odoo, the password is odoo, the default database is postgres).

To open up the connection to the database, we use docker exec to run pqsl inside the container.

 

 

Tailing or Reading Log

The simplest way to monitor logs while working locally is through the docker logs command. You can list, grep, and tail logs for a specific container. Here is an example of tailing logs on one of the Odoo container’s we’ve created:

 

A Note on Docker Compose

In Dockerizing Odoo, I utilized docker-compose, and I still recommend using it if you start to depend on Docker for your development. It feels like a must-have utility for the sake of efficiency.

But I’m thinking about the total beginners here. The Odoo developers who are just playing around with Docker for the first time and using Docker directly helps you learn more because of how explicit the API is, and it’s also simpler on a small scale (one or two containers).

As you learn more and get more comfortable with docker, I recommend going back to look at my original article and start reading through the Docker Compose documentation.

Wrapping Up

That’s the basics for simple local Odoo development techniques using Docker. Try them out, and let me know what you think. I hope it’s able to simplify your workflow or your team’s workflow!

Best of luck coding.

– Holden Rehg

Thanks For Reading

I appreciate you taking the time to read any of my articles. I hope it has helped you out in some way. If you’re looking for more ramblings, take a look at the entire catalog of articles I’ve written. Give me a follow on Twitter or Github to see what else I’ve got going on. Feel free to reach out if you want to talk!

“Without an in-house developer, we’ve relied on Blue Stingray to help us launch our online store. Without them, we would have never gotten off the ground.”

— Adrian Southern, Director, Innova Disc Golf
Have a project? Get In Touch