Contents
Roadmap info from roadmap website
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to create, manage, and run your applications using a simple YAML file called docker-compose.yml
. This file describes your applicationโs services, networks, and volumes, allowing you to easily run and manage your containers using just a single command.
Some of the benefits of using Docker Compose include:
- Simplified Container Management: Docker Compose allows you to define and configure all your services, networks, and volumes in one place, making it easy to manage and maintain.
-
Reproducible Builds: Share your
docker-compose.yml
file with others to make sure they have the same environment and services running as you do. - Versioning Support: Docker Compose files can be versioned for easier compatibility across different versions of the Docker Compose tool itself.
Creating a Docker Compose File
To create a docker-compose.yml
file, start by specifying the version of Docker Compose you want to use, followed by the services you want to define. Hereโs an example of a basic docker-compose.yml
file:
version: "3.9"
services:
web:
image: nginx:latest
ports:
- "80:80"
depends_on:
- db
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: mysecretpassword
In this example, we have specified two services: a web server (web
) running the latest version of the nginx image, and a database server (db
) running MySQL. The web server exposes its port 80 to the host machine and depends on the launch of the database (db
). The database server has an environment variable set for the root password.
Running Docker Compose
To run your Docker Compose application, simply navigate to the directory containing your docker-compose.yml
file and run the following command:
docker-compose up
Docker Compose will read the file and start the defined services in the specified order.
Other Useful Commands
-
docker-compose down
: Stops and removes all running containers, networks, and volumes defined in thedocker-compose.yml
file. -
docker-compose ps
: Lists the status of all containers defined in thedocker-compose.yml
file. -
docker-compose logs
: Displays the logs of all containers defined in thedocker-compose.yml
file. -
docker-compose build
: Builds all images defined in thedocker-compose.yml
file.
Thatโs a brief introduction to Docker Compose! For more information, check out the official Docker Compose documentation.