Containers

Docker Development Environment: Test your Containers with Docker Desktop

Docker Development Environment for testing self-hosted containers and setup and configuration to streamline your home lab projects.

One of the benefits of a Docker container is it allows you to have quick and easy test/dev environments on your local machine that are easy to set up. Let’s see how we can set up a Docker development environment with Docker Desktop.

Quick overview of Docker Development Environment

Dev Environments allow you to set up a configurable development environment with all the necessary code and tools, enabling a quick start to your projects.

It uses tools integrated into code editors, like VS Code, which allows Docker to access code mounted in a container instead of on your local host. This setup separates the tools, files, and running services on your machine, allowing multiple versions to exist with each other.

Docker dev environments work the GUI in Docker Dashboard in Docker Desktop or directly from your terminal with the new docker dev CLI plugin, allowing it to work with different preferences and workflows.

Note the following high-level view of features:

FeatureDescription
Configurable EnvironmentsSet up development environments tailored to project requirements.
Integrated Code EditorsWork with popular code editors like Visual Studio Code for a streamlined workflow.
compose-dev.yaml FileDefine environment configurations including services, networks, and volumes.
Docker Desktop GUIManage containers, images, and environments through an intuitive graphical interface.
docker dev CLI PluginTerminal-based interaction with environments for command-line enthusiasts.
Git IntegrationSeamless interaction with existing Git repositories for version control.
Docker Desktop ExtensionsExtend capabilities by integrating additional tools and services.
Multi-Project SupportWork on multiple projects simultaneously with isolated environments for each.
Dependency ManagementDefine and manage project dependencies systematically.
Container InteractionStart, stop, and manage containers, access terminal of running containers.

Setting Up Your Docker Development Environment with Docker Desktop

Docker Desktop is a great tool that you can use to have a GUI tool to interact with Docker, especially on Windows machines. One of the features of the Docker Desktop tool is the Dev Environment.

At the heart of this setup lies a special file named compose-dev.yaml, residing at the root of your projectโ€‹2โ€‹. This file is the cornerstone for instructing Docker Desktop on how to build, start, and utilize the correct image for your services.

Hereโ€™s a simplified breakdown of the setup process:

  1. Install Docker Desktop: Ensure you have the latest version installed on your machine.

  2. Create or Clone Your Project: Either initiate a new project or clone an existing Git repo to your local machine.

  3. Compose Your Environment: Craft your compose-dev.yaml file with the necessary configurations to define your services, networks, and volumes.

  4. Launch Docker Dev Environment with CLI: With a simple command, bring up your Docker Dev Environment

1. Install Docker Desktop

Download Docker Desktop here: Docker Desktop. Run the installer.

Installing docker desktop with wsl
Installing docker desktop with wsl

2. Create or clone your project

Click the Dev Environments (Beta) menu. Then Create a new enviroment.

Create a new docker dev environment
Create a new docker dev environment

Docker Desktop allows you to either source your code from a folder or use a Git repository.

Setting up a docker dev environment
Setting up a docker dev environment

On the Setup screen > Choose source, you can select between Existing Git repo or Local directory. Here I am choosing local directory.

Choose the source of the docker dev environment
Choose the source of the docker dev environment

Do you have to have an existing Docker Compose file for it to work with for your Docker Development Environment? No, you actually don’t. If there is no docker-compose file in the directory, a generic one will be created for you.

Below is the contents of the default compose-dev.yaml file:

services:
  app:
    entrypoint:
    - sleep
    - infinity
    image: docker/dev-environments-default:stable-1
    init: true
    volumes:
    - type: bind
      source: /var/run/docker.sock
      target: /var/run/docker.sock

The default Docker image configurations will start pulling.

Preparing starting the environment
Preparing starting the environment

You will see the default environment successfully built and ready.

Dev environment is built and ready
Dev environment is built and ready

You can choose to open in Visual studio code editor by default.

Open in vs code
Open in vs code

Below, the default compose-dev.yaml file is opened in VS code.

Viewing the compose dev.yaml file in vs code
Viewing the compose dev.yaml file in vs code

3. Compose your Docker Development Environment

If you want to compose a new dev environment container, you can do that with your own code. You can use a normal docker-compose.yml file with your own custom configurations as you would spinning up containers per normal with Docker Compose.

Below, I am using a custom Docker Compose file to spin up Gitea.

version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.20.5
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"

After the Docker container image is pulled and configured, we see our Gitea container up and running.

Running gitea in a docker development environment
Running gitea in a docker development environment

4. Launch Docker Dev environment with CLI

You can also launch Docker Dev environments with the docker dev CLI tool. You can see the output of the Docker Dev CLI tool with the following:

docker dev --help

The docker dev command line tool has the following parameters:

  • check – Check dev environments

  • create – Create a new dev environment

  • list – lists all dev environments

  • logs – traces logs from a dev environment

  • open – open dev environment with the IDE

  • rm – removes a dev environments

  • start – starts a dev environment

  • stop – stops a dev environment

  • version – show the Docker Dev version information

Running the docker dev command line
Running the docker dev command line

Docker dev environment extensions

You can also use Docker Desktop Extensions. These extend what you can achieve with your setup. Extensions enable integrating tools with your docker development environment.

If your project requires a specific set of development tools or services, Docker Desktop Extensions can help incorporate these into your environment.

Add extensions in docker desktop
Add extensions in docker desktop

Working with Docker and Visual Studio Code

As seen above, Visual Studio Code, works really well with Docker Desktop. You can use VS Code to write Dockerfiles, manage containers, or even interact with Docker CLI.

Hereโ€™s how you can use Visual Studio Code in tandem with Docker:

  1. Install Docker Extension: Get the Docker extension for Visual Studio Code

  2. Access Docker Dev Environment: With the extension installed, access and manage your Docker Dev Environment from the IDE.

When you choose to open in Visual Studio Code, you will see it starting the Dev container in the VS Code interface:

Starting the dev container in vs code
Starting the dev container in vs code

Wrapping up

Using Docker Desktop as a Docker development environment is a great way to test and develop with Docker containers. Developers and DevOps engineers will benefit from using the tool in the environment to work with their code and other aspects of running containers.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

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

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