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.

Quick Summary

  • 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.
  • 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.
  • 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 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

Frequently Asked Questions

Can Docker Dev environments work with existing Git repositories?

Docker Desktop simplifies the setup of dev environments by providing a centralized platform where developers can manage Docker containers and images. It integrates with code editors like Visual Studio Code and supports using a compose-dev.yaml file to define the environment configurations, making it easier to create, manage, and share dev environments across the team.

 
How does the docker dev CLI plugin enhance the developer experience?

The docker dev CLI plugin offers a terminal-based interface to interact with your Docker Dev Environments. This is especially handy for developers who prefer using the terminal over GUI. It provides quick commands to manage your environments, making it a practical tool for streamlining development workflows.

What’s the role of a compose-dev.yaml file in Docker Dev Environments?

The compose-dev.yaml file is crucial as it holds the configuration necessary for Docker Desktop to understand how to build, start, and use the right image for your services. It defines the architecture of your dev environment, specifying services, networks, and volumes, thereby creating a blueprint for Docker to follow.

Are there any special considerations for managing dependencies in Docker Dev Environments?

Managing dependencies in Docker Dev Environments is straightforward. You can define all necessary dependencies in the compose-dev.yaml file or through Dockerfiles, ensuring your environment has all the required tools and libraries. It’s a systematic way to keep your dev environment consistent and reproducible.

What are Docker Desktop Extensions?

They integrate additional tools and capabilities into your dev environment. Extensions allow you to customize your environment with functionality you may need for a specific project

How do I interact with running containers in Docker Dev Environments?

Interacting with running containers is carried out using the Docker Desktop’s GUI or the docker dev CLI plugin. You can start, stop, and manage containers directly, and even access the terminal of running containers to execute commands or troubleshoot issues.

Can I work on multiple projects simultaneously with Docker Dev Environments?

Yes, Docker Dev Environments support working on multiple projects simultaneously. Each project can have its own isolated dev environment, allowing you to switch between projects easily without any interference between them. This is especially useful when different projects have varying dependencies and configurations.

How does Docker Desktop enhance the dev environment setup?

Docker Desktop simplifies the setup of dev environments by providing a centralized platform where developers can manage Docker containers and images. It integrates with code editors like Visual Studio Code and supports using a compose-dev.yaml file to define the environment configurations, making it easier to create, manage, and share dev environments across the team.

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 has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon 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.

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.