Skip to content
Home » My Blog Tutorial » Tutorial Create a Custom Docker Image for Odoo Development

Tutorial Create a Custom Docker Image for Odoo Development

Docker Logo

Creating a custom Docker image is a great way to ensure that all the necessary libraries and dependencies are pre-installed, making your development environment consistent and efficient. In this tutorial, we’ll show you how to create a custom Docker image for Odoo that includes libraries for debugging in VSCode.

In this tutorial, we will guide you on how to create a custom Docker image for Odoo development. By including essential libraries, you can streamline your debugging process in VSCode. Custom Docker images ensure that your development environment is consistent and efficient.

Step 1: Create a Dockerfile

First, you need to create a Dockerfile. This file will contain instructions for building your custom Docker image. Add the following lines to your Dockerfile:

FROM odoo:17

USER root

COPY ./requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt
RUN rm /requirements.txt

These instructions do the following:

  • FROM odoo:17: This line specifies the base image, which is Odoo version 17.
  • USER root: Switches to the root user to have the necessary permissions to install libraries.
  • COPY ./requirements.txt /requirements.txt: Copies the requirements.txt file from your local machine to the Docker image.
  • RUN pip3 install -r /requirements.txt: Installs the libraries listed in requirements.txt.
  • RUN rm /requirements.txt: Removes the requirements.txt file from the Docker image after the libraries have been installed.

Step 2: List the Required Libraries

Next, create a requirements.txt file in the same directory as your Dockerfile and add the following lines:

debugpy
pydevd-odoo

These libraries are necessary for debugging Odoo applications in VSCode:

  • debugpy: A debugger for Python.
  • pydevd-odoo: An extension for debugging Odoo applications.

Step 3: Build the Docker Image

Once you have your Dockerfile and requirements.txt set up, you can build your custom Docker image. Open your terminal and navigate to the directory containing your Dockerfile. Then, run the following command:

docker build -t odoodev:17.0 -f Dockerfile .

This command builds a Docker image named odoodev with the tag 17.0 using the instructions in the Dockerfile. The -f Dockerfile specifies the Dockerfile to use for the build.

Step 4: Use the Custom Docker Image in Docker Compose

Finally, you can use your custom Docker image in a Docker Compose setup. Here’s an example of how to configure your docker-compose.yml file to use the custom image:

version: '3.8'

services:
  odoo:
    image: odoodev:17.0
    ports:
      - "8069:8069"
    volumes:
      - odoo-data:/var/lib/odoo
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo

  db:
    image: postgres:13
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=odoo
      - POSTGRES_PASSWORD=odoo
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  odoo-data:
  db-data:

In this docker-compose.yml:

  • The odoo service uses the custom image odoodev:17.0.
  • The db service uses the official PostgreSQL image.
  • The necessary environment variables and volumes are configured for both services.

Conclusion

By following these steps, you’ll create a custom Docker image that includes the necessary libraries for debugging Odoo in VSCode. This setup ensures that your development environment is consistent and ready for efficient debugging. If you have any questions or need further assistance, feel free to reach out.

For more information on Docker and Odoo, check out the official Docker documentation and Odoo’s documentation.

Several articles offer valuable guidance on debugging Odoo in Visual Studio Code (VS Code). These resources odoo 14 [1] [2], 15, 16, 17 [1] cover essential topics such as setting up the development environment, configuring the launch.json file, and leveraging VS Code’s debugging features. Additionally, they provide tips on setting breakpoints, inspecting variables, and stepping through the code. By following these tutorials, developers can efficiently debug Odoo applications and enhance their coding workflow.

Happy coding!


Discover more from teguhteja.id

Subscribe to get the latest posts sent to your email.

Leave a Reply

Optimized by Optimole
WP Twitter Auto Publish Powered By : XYZScripts.com

Discover more from teguhteja.id

Subscribe now to keep reading and get access to the full archive.

Continue reading