Developing inside a Container

I’m contributing to Sonarqube-Sql-Plugin (https://github.com/erictummers/sonar-sql-plugin) and creating pull requests to merge back my changes. Getting my environment setup was easy using homebrew (https://brew.sh) but still required some work. Here is how VSCode makes this much easier with developing inside a container.

Container

With docker you can start an isolated environment that is created to do one thing – host the software. The container is setup with all the dependencies and settings needed during the initial build, so we can just use them. Installation is easy with docker desktop (https://www.docker.com/products/docker-desktop)

VSCode now has an extension that you can use to run the development environment inside a container. I installed the remote containers extension (https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) and added the .devcontainer folder. The dockerfile contents I copied from Microsoft’s sample container for java (https://github.com/microsoft/vscode-dev-containers/tree/main/containers/java/.devcontainer) Now I can dev – build – repeat in a container.

VSCode project

After reopening the project in the container (F1 > Remote-Containers: Rebuild and Reopen in Container) VSCode started loading everything I needed to develop. Me being a Microsoft developer, I didn’t know the pom.xml contained the build target information. The maven build targets are offered with a run button next to them for easy use. I was able to build the jar file and test it within minutes.

The .devcontainer folder can be added to Github so everyone can use it. No more “works on my machine” 😉

References

developing inside a container – vscode (https://code.visualstudio.com/docs/remote/containers)

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development, Tooling and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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