Building a Containerized Dev Environment from Scratch with Docker

Goals

The goal here was to create a Docker container with all the dev tools I wanted for a basic infrastructure/DevOps environment for me to use as my learning playground. This setup allows me to clone repositories, write IaC configurations, run Ansible playbooks, deploy infrastructure with Terraform, interact with Azure through the CLI, and manage Kubernetes clusters with Kubectl—all from a single, portable environment that I self host. Now when I say portable this is because in my case I use a VPN to connect back to my home lab server where this vscode server container and repositories live and the environment is also browser-based.

Tools Included:

  • VS Code (code-server)
  • Git
  • Ansible
  • Terraform
  • Azure CLI
  • Kubectl
  • Docker CLI
  • Various networking tools

Pre-requisites

  • Machine with Linux OS (Sever, VM, Computer)
  • Basic understanding of Docker and Docker Compose
  • Docker and Docker Compose installed
  • (Optional) VPN Server or Reverse Proxy for remote access

Setting Up

1. Setting Up the Workspace

First, create a new directory for the project:

Inside this directory, we’ll need two key files: `Dockerfile` and `docker-compose.yml`. Use the following commands to create these files:

2. Understanding the Dockerfile

The `Dockerfile` is really the blueprint for the container image so it’s important to know the basics. Here’s a brief high-level overview of what’s inside my Dockerfile in my dev_env repository:

  • Base Image – Starts with Ubuntu 20.04 for stability and support.
  • Essential Tools I Wanted  – Installation of native tools like `curl`, `git`, `python3`, etc.
  • Networking Tools –  like ping and net-tools for basic network troubleshooting.
  • Installation Scripts – Using `curl` to fetch and install nonnative tools like Ansible, Terraform, Azure CLI, and kubectl.
  • VS Code – Obviously the meat of the project so a curl to install code-server to enable VS Code in the browser.

Here’s a snippet from the Dockerfile:

3. Docker Compose Config

The `docker-compose.yml` file specifies how Docker should run the environment. Key parts to know here are:

  • Volumes – directories or files to mount from the host
  • Ports –  Maps ports between the container and host machine.
  • Environment Variables – In this case it sets a password for code-server authentication.

Here’s a snippet from the docker-compose.yml:

4. Building the Container Image

With the to files completed to build the container that you made or by just copying and pasting my repository, navigate to the directory where `Dockerfile` and `docker-compose.yml` are stored and run:

This command builds the container image by processing the Dockerfile specified in the docker compose file.

5. Run the Container

To start the container, use the command:

You can verify  the container is up with:

Once the container is up, you should be able to access code-server at `http://<yourhostIP>:1123` and log in with the authentication password you set in the docker compose file.

And that’s it.  You now have a versatile dev environment that you can use anywhere. Hope you find that as cool as I do and happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top