Using Docker Compose

Using Docker Compose

docker-compose depends on the file called docker-compose.yml,the settings and clusters depends on this file

the format of the file

container_name:
property: value
- or options
  • so here we will see one example we will connect two containers node.js application to Redis container
  • we should name to the container in the below format like in the below example the name of the container is web
web:
build: .
  • to link the two containers we need to specify link property, in this example we will link to Redis source container
links:
- redis
  • now the same format is used to setup ports for containers
ports:
- "3000"
- "8000"
  • for defining the second container, use below format
redis:
image: redis:alpine
volumes:
- /var/redis/data:/data
  • after creating docker-compose.yml file, you can launch the container with the up command
for single container
up <name>
default
docker-compose up -d

-d states to run containers in the background

  • to see details of launched containers, you can use below command
docker-compose ps
  • to see log details
docker-compose logs
  • to stop all the containers
docker-compose stop
  • to remove all the containers
docker-compose rm
Last updated on by vishal devxo