Docker development environment on Visual Studio Code.

Matheus Villela Torres
3 min readJul 12, 2021

--

Visual Studio Code and Docker logos.

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.

Requirements:

  • Visual Studio Code;
  • Docker;
  • Remote - Containers extension.
Remote — Containers extension.

Hands-On:

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 :

Dockerfile and requirements examples.

Then, using the remote-containers extension select a folder to open in a container (notice here that i’m not attaching any volume).

Type F1 and find remote-containers extension.

Choose the Dockerfile option.

Configuration files selection.

Aaaaand, that’s it, your environment soon will be created with all your requirements.

Image build.

Now you can run tests and never say again: “but it works on my machine”.

Run commands inside the docker container.
Ports are automatically created.

That’s it for today. Hope it helps.

P.S. it is possible to install Visual Studio Code extensions inside the new containerized environment.

Installing Code Runner in Dev Container.
Local and Dev (container) VS Code installed extensions.

--

--