Docker development environment on Visual Studio Code.
How many times have you tested your code on your machine and when you Pull/Merge request, the pipeline breaks because you missed the last package that you installed to implement a new feature?
To avoid issues like that I developed a strategy, to always code inside a docker environment and run my tests inside of it. That’s great, but it’s annoying creating a container, name it, attach a volume, expose a port, every time.
So, for those who are unfamiliar, Visual Studio Code has an extension called “Remote - Containers”, that makes it much easier, check it out.
- Visual Studio Code;
- Remote - Containers extension.
If you already installed the requirements, that’s no secret here, you just need to create your Dockerfile and the requirements list (e.g for python) inside your project folder, just like this :
Then, using the remote-containers extension select a folder to open in a container (notice here that i’m not attaching any volume).
Choose the Dockerfile option.
Aaaaand, that’s it, your environment soon will be created with all your requirements.
Now you can run tests and never say again: “but it works on my machine”.
That’s it for today. Hope it helps.
P.S. it is possible to install Visual Studio Code extensions inside the new containerized environment.