Develop your code inside a Docker Container using your favorite IDE

Idan Mor (sidanmor)
sidanmor
Published in
3 min readOct 7, 2020

--

Docker lets you package your software into standardized units for Development, Shipment, and Deployment. Docker image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings. Docker images become containers at runtime when running on a Docker Engine, so the application runs quickly and reliably, and can transfer from one computing environment to another.

This blog talks about the development stage and the development environment. How can you be sure that what runs on your personal computer, will run and do the same thing inside the docker container? How can you be sure that you have all of the needed dependencies? How can you be sure that you have the same environment settings among your other team members? The answer to all of these questions is that you can never be sure.

What if you could run and even debug your code inside the docker container itself, on your personal computer? What if you didn’t need to spend half a day or more on installing all the needed packages and tools to have the ability to run your code on new employees’ personal computers?

You can do it easily with your favorite IDE (VSCode, WebStorm, or PyCharm). You simply need to have a Docker Engine installed on your personal computer.

Visual Studio Code:

You need to use the Microsoft “Remote Containers” extension (you will see an “open a remote window” button at the bottom left of your window). Press on it and select the “Reopen in Container” option. If you already have a Dockerfile, you can select the “From Dockerfile” option and you will have a new Container referring to the existing Dockerfile to run your code inside of it.

If you don’t have a Dockerfile, you can use a basic container configuration from the container definition registry. Select the “From a predefined container configuration definition” option, and then add the Development Container Configuration Files you want. A new window with the container will appear and you will be able to run your code inside of it. Additionally, you will have the Development Container Configuration Files in the .devcontainer folder for future runs.

WebStorm/Pycharm:

Javascript and Python are interpreter languages, so you can use Docker container inner-interpreter instead of using the local interpreter. With the Docker container, you can run and debug your code while developing it. Using three clicks or less, you can set the docker image that you already have in production, to be your development environment interpreter.

Go to Preferences | Build, Execution, Deployment | Docker, and set a new docker Execution engine. You can select your docker engine from a remote machine, or you can use your local docker engine.

  1. Go to Preferences | Project: backend | Project Interpreter and set a new docker Project interpreter. You can use any Docker image you want. (an image from DockerHub or one that you built from your Dockerfile)
  2. Go to Run/Debug Edit Configurations and set the interpreter to be the interpreter you just set in the previous step. There, you can also edit the docker container settings.
  3. Done.

Having the ability to run and debug your code inside the docker container can save you a huge amount of time. For one, you do not need to install anything on your personal computer. Secondly, you can be sure that all of your team members have the same environment settings. Thus, if you manage to run it properly on your personal computer, it will run properly in production.

--

--

Full-Stack Team Leader, Senior Full-Stack Software Engineer and Javascript Ninja