Dev Container: Develop Inside a Docker Container

The more connected our applications are, the more complex their development is. The days when an application talked only to a database seem to be a thing of the past. Today, our applications connect to the cloud, talk to various services, and are often connected to multiple social networks.

We need more and more infrastructure to run this kind of applications. Not only in production, but also at development time. For a while it was a feasible approach to install all the dependencies on your developer machine. Unfortunately, the more applications we maintain the more likely are version conflicts in the dependencies.

Our approach with installing the whole infrastructure on the development machine is reaching its limits and no longer scales with current requirements. It is time for something different.

 

Dev Containers to the rescue?

Docker is not only a great tool to run your applications in production, but it also offers superb advantages at development time. You can put your application and all the depending services into containers and run them in Docker – no need to install them all on your development machine. Incompatible versions or already used ports no longer matter – all is nicely put into their own box, and you run what you need when you need it.

The Docker integration in IDEs like Visual Studio Code improved so much that we now get an effective and smooth workflow. We create a container with our codebase, connect to it with our IDE and get immediate feedback when we change something. All we need for that is Docker, Git, and an IDE. If we need another runtime for our code, we get another Docker image and are good to go. This allows us to get the old Ruby version we need in a legacy application the same way we get the newest version to check if our application still works.

The best part for me is that we can put our development environment into a container and still use dedicated servers for production if we want to. We can dip our toes into the container waters without fully committing to use it everywhere. If it works, great! If not, we drop some files in our code repository and go back to the old ways.

 

Limitations

Unfortunately, it only works reliably with Linux containers. You can run them on Windows, but make sure that you use the Linux container format. The Windows container format is an endless obstacle course and I advise strongly against it.

For everything that offers no container support you still need your test environment. It may take a bit more work, but you still can profit from dev containers.

 

Preparation

You need a running Docker installation on your development machine. The installation guides at Docker.com should help you with this. If you use Docker Desktop for Windows, make sure that you install it as administrator.

 

Next

Next week we create a dev container to develop a Ruby application – without installing Ruby on our machine.

6 thoughts on “Dev Container: Develop Inside a Docker Container”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.