How to use odoo:17 image in devcontainer?
I am trying to create a devcontainer for the development of custom Odoo modules. This devcontainer is based on the official odoo:17 image. You can see the current state of my devcontainer in my-odoo-project.zip. I would like to ask the following questions:
-
It took me a few days of effort to discover that I needed to add a new user with UID/GID 1000 in the
odoo:17image to make the devcontainer work with this image. See the creation of thedeveloperuser in.devcontainer/Dockerfile.fajnodoo17and the"remoteUser"in.devcontainer/devcontainer.json. Here are my questions:- Is creating a user with UID/GID 1000 the only solution, or is there a more straightforward alternative?
- If user creation is the correct approach, is it possible to pre-create such a devcontainer-friendly user in the Docker image to make it easily usable for a devcontainer creation? Or at least, is it possible to add a section "How to use this image in a devcontainer" in the
odoo:17image overview describing how to extend the image by user creation?
-
How can I map the installed Odoo modules (applications) to my devcontainer? Where are they located in the
odoo:17image? -
How can I run
odoo-bincommand in the devcontainer (or Docker container)? -
Do you have any other recommendations on how to correctly use the
odoo:17image in a devcontainer for development? Would it be possible to include these recommendations in theodoo:17image overview?
@mojmirdurik I have made a tutorial about this. https://teguhteja.id/debug-odoo-17-in-docker-using-vscode/
Hopefully this can help your problem If you feel this is enough then we can close this issue
@teguhteja Thank you for the tutorial. To make it functional out of the box, I have made the following changes:
- I have added
[options]at the beginning of theodoo.conffile. - I have corrected the
POSTGRES_USERandPOSTGRES_PASSWORDindocker-compose.yamlto match the values provided inodoo.conf. Additionally, I have added theHOST,USE, andPASSWORDenvironment variables to theodooservice (see Odoo Docker Hub page > "Docker Compose examples").- You might want to change (or remove) the ports mapping
- '5432:5432'in thedbservice to avoid conflicts with a local installation of Postgres.
- You might want to change (or remove) the ports mapping
Your tutorial allows developing Odoo custom modules without installing Odoo locally. However, the proposed approach differs from the devcontainer approach because the IDE (VS Code) does not see the Odoo environment. This means that if I have not installed Python locally or if I want to use some Python packages installed by requirements.txt inside the odoodev:17.0 image, the IDE will show errors for unknown packages. Am I wrong? I am new to Python & Odoo, so please correct me if I am mistaken.
What I need is for the IDE to run inside the Odoo Docker container. That is exactly what devcontainers are designed for.
How do you share the same Odoo development environment among all team members?
Hi @mojmirdurik
I am happy with the advice you give to me. I'll change that on my github. I will try some of the things above I am going answer your question :
-
the IDE (VS Code) does not see the Odoo environment
yes this correct
-
This means that if I have not installed Python locally or if I want to use some Python packages installed by requirements.txt inside the odoodev:17.0 image, the IDE will show errors for unknown packages. Am I wrong? I am new to Python & Odoo, so please correct me if I am mistaken.
Yes, you are right. there will likely be errors. but why do you need python or python packages?
-
What I need is for the IDE to run inside the Odoo Docker container. That is exactly what devcontainers are designed for.
In the past, I created an Ubuntu container containing odoo and postgresql (this is bad practice) and this could run the devcontainer. but this takes up a lot of resources and a large container size. I'll try to research it with the existing vscode devcontainer tutorial + docker odoo tutorial. Hopefully you can run devcontainer with the approach you need.
-
How do you share the same Odoo development environment among all team members?
My previous company used VMware + Ubuntu inside Odoo because the standard OS was Windows and shared virtual disks. I tried to give docker advice but this approach requires a long learning time. Currently I am working alone and holding many versions of the Odoo project in use, so the approach in this tutorial is quite easy for me to work with.
-
How can I run odoo-bin command in the devcontainer (or Docker container)?
you can run
odooand checkodoo --version
Hi @mojmirdurik
it seems like this devcontainer method is quite specialized and not many people use it for odoo + devcontainer.
i tried to find some tutorials but instead found some of these repos. maybe you can ask your question there.
- https://github.com/m3r3nix/odoo-dev-container
- https://github.com/jeffery9/odoo-devcontainer
- https://git.ejaferp.com/tasks/task1/-/blob/main/.devcontainer.json?ref_type=heads
and thank you for your explanation. i learned a lot from there