2018-10-12 15:37:13 -04:00
---
title: Docker compose
---
2019-05-12 13:25:28 -04:00
## Docker Compose
2018-10-12 15:37:13 -04:00
2019-05-12 13:25:28 -04:00
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services.
2018-10-12 15:37:13 -04:00
2019-05-12 13:25:28 -04:00
The steps to use docker-compose are:
2018-10-12 15:37:13 -04:00
2019-05-12 13:25:28 -04:00
1. Create a Dockerfile which defines the image and can be producible everywhere.
2. Create a docker-compose yml file to run the services.
3. Use docker-compose up to start the sevices specified in docker-compose.yml file.
2018-10-12 15:37:13 -04:00
#### Basic commands in docker-compose
* Command to run docker-containers
```
docker-compose -f docker-compose.yml up
```
* Command to run containers in detached mode
```
docker-compose -f docker-compose.yml up -d
```
2018-12-21 07:54:15 +05:30
* Command to run containers after building the images again (Note: docker containers automatically builds at the first time)
2018-10-12 15:37:13 -04:00
```
docker-compose -f docker-compose.yml --build -d
```
2018-12-21 07:54:15 +05:30
* Command to stop containers when running in detached mode
2018-10-12 15:37:13 -04:00
```
docker-compose -f docker-compose.yml down
```
2018-10-28 16:08:28 +01:00
* Command to remove service containers
```
docker-compose -f docker-compose.yml rm
```
* Command to pull Images for all service containers from repository (by default from Docker Hub)
```
docker-compose -f docker-compose.yml pull
```
* Command to view logs of all service contaienrs (add -f to follow logs)
```
docker-compose -f docker-compose.yml logs
```
2018-10-12 15:37:13 -04:00
#### More Information:
2018-10-28 16:08:28 +01:00
- [More information on Docker-compose ](https://docs.docker.com/compose/ )
2018-10-12 15:37:13 -04:00