Introduction to Docker Compose
Docker Compose is a tool that allows you to define and run multi-container Docker applications. It simplifies the process of managing and orchestrating multiple Docker containers by providing a declarative configuration file, known as the docker-compose.yml
file.
With Docker Compose, you can easily define the services, networks, and volumes that make up your application, and then use a single command to start, stop, and manage the entire application stack.
Here's an example of a basic docker-compose.yml
file:
version: "3"
services:
web:
image: nginx:latest
ports:
- "80:80"
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
This file defines two services: a web server running Nginx and a MySQL database. The web
service exposes port 80 on the host, while the db
service sets the MySQL root password.
To start the application, you can simply run the following command in the same directory as the docker-compose.yml
file:
docker-compose up -d
This will start the application in detached mode, and you can then access the web server at http://localhost:80
.
Docker Compose provides a wide range of features and configuration options, allowing you to define complex, multi-container applications with ease. In the following sections, we'll explore how to use Docker Compose with host network configuration.