Set up a dev environment

Dev Environments is changing

We’re working hard to make Dev Environments work even better for you and your teams. In the coming months, we’ll be introducing a new vision for Dev Environments.

In the mean time, it may take us longer to respond to requests for support.

Changes to Dev Environments with Docker Desktop 4.13

Docker has simplified how you configure your dev environment project. All you need to get started is a compose-dev.yaml file. If you have an existing project with a .docker/ folder this is automatically migrated the next time you launch.

If you are using .docker/docker-compose.yaml, we move it to ../compose-dev.yaml. If you are using .docker/config.json, we create a ../compose-dev.yaml file with a single service named "app”. It is configured to use the image or Dockerfile referenced in the JSON as a starting point.

To set up a dev environment, there are additional configuration steps to tell Docker Desktop how to build, start, and use the right image for your services.

Dev Environments use an compose-dev.yaml file located at the root of your project. This file allows you to define the image required for a dedicated service, the ports you'd like to expose, along with additional configuration options.

The following is an example compose-dev.yaml file.

version: "3.7"
      context: backend
      target: development
      - db-password
      - db
    image: mariadb
    restart: always
      test: [ "CMD", "mysqladmin", "ping", "-h", "", "--silent" ]
      interval: 3s
      retries: 5
      start_period: 30s
      - db-password
      - db-data:/var/lib/mysql
      - MYSQL_DATABASE=example
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db-password
      - 3306
    build: proxy
      - 8080:80
      - backend
    file: db/password.txt

In the yaml file, the build context backend specifies that that the container should be built using the development stage (target attribute) of the Dockerfile located in the backend directory (context attribute)

The development stage of the Dockerfile is defined as follows:

# syntax=docker/dockerfile:1
FROM golang:1.16-alpine AS build
WORKDIR /go/src/
COPY . .
RUN go build -o server .
FROM build AS development
RUN apk update \
    && apk add git
CMD ["go", "run", "main.go"]
FROM alpine:3.12
COPY --from=build /go/src/ /server
CMD ["/server"]

The development target uses a golang:1.16-alpine image with all dependencies you need for development. You can start your project directly from VS Code and interact with the others applications or services such as the database or the frontend.

In the example, the Docker Compose files are the same. However, they could be different and the services defined in the main Compose file may use other targets to build or directly reference other images.

What's next?

Learn how to distribute your dev environment