The following sections detail configuration options specific to the development environment of the Docker CLI.
Docker Compose Configuration
The primary tool for configuring services within your Docker development environment is docker-compose.yml
. Below is an example configuration file that illustrates how different services are defined, their dependencies, build contexts, and network configurations.
version: "2"
services:
server:
build:
context: .
dockerfile: server.Dockerfile
networks:
- mdb
- sig
ports:
- "8080"
- "4443:4443"
entrypoint: /usr/bin/env sh
command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json"
depends_on:
- mysql
- signer
signer:
build:
context: .
dockerfile: signer.Dockerfile
networks:
mdb:
sig:
aliases:
- notarysigner
entrypoint: /usr/bin/env sh
command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json"
depends_on:
- mysql
mysql:
networks:
- mdb
volumes:
- ./notarysql/mysql-initdb.d:/docker-entrypoint-initdb.d
- notary_data:/var/lib/mysql
image: mariadb:10.4
environment:
- TERM=dumb
- MYSQL_ALLOW_EMPTY_PASSWORD="true"
command: mysqld --innodb_file_per_table
volumes:
notary_data:
external: false
networks:
mdb:
external: false
sig:
external: false
Breakdown of Configuration
Version: Indicates which version of the Docker Compose file format is being used. In this case, version 2 is selected for better compatibility with older Docker versions.
Services: Each service is defined with attributes including:
build: Determines the context and specific Dockerfile for building the service. For example, the
server
service specifies its context as.
and the Dockerfile asserver.Dockerfile
.networks: Lists the networks the service connects to. Services may belong to multiple networks. For example, the
server
service connects to bothmdb
andsig
.ports: Maps the container ports to the host system. For instance, the
server
exposes ports8080
and4443
.entrypoint: Sets the command that is executed when the container starts. Here, it is using
sh
to run the subsequent command.command: This allows for a custom command to be executed inside the container upon startup. The command first runs migrations and then starts the respective services using configuration files.
depends_on: Specifies service dependencies to ensure that dependent services start in the correct order.
Volumes: This section provides persistent storage for the MySQL service. It maps a directory (
./notarysql/mysql-initdb.d
) from the host to an initialization directory in the container. The volumenotary_data
is used to persist MySQL data across container restarts.Networks: Defines custom networks for inter-service communication. Both
mdb
andsig
are configured as non-external networks.
Building the Project
In the context of building the Docker images, the build command should be run only after confirming the configuration is correct. Use the following command to build the specified services defined within docker-compose.yml
:
docker-compose build
Running the Development Environment
Once the images are built, bring up the containers defined in the docker-compose.yml
configuration with:
docker-compose up
This command will start all defined services and respect the dependencies set. Logs of the output can be inspected directly in the terminal.
Environment Variables
In the context of the mysql
service, several environment variables are defined:
TERM=dumb
: This is set to avoid terminal issues that might arise since MySQL does not require a terminal interface.MYSQL_ALLOW_EMPTY_PASSWORD=true
: This allows MySQL to start without requiring a password for the root user, simplifying local development configurations.
Conclusion
This section has provided an overview of configuring a Docker-based development environment by leveraging a docker-compose.yml
file. The settings illustrate how to define service dependencies, manage persistent storage, and control networking between services.
Source: docker/cli GitHub Documentation