Installing

You can try install docker compose in two method, apt package managing or manually. Read more at

Use apt package

sudo apt install docker-compose-plugin -y

Manually download

  1. To download and install the Compose CLI plugin, run
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
  1. Apply executable permissions to the binary
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

Basic command

Info

With docker-compose, you can find and explore more about this technicals with documentation in details, such as

up and stop command which commonly use to bring up and down the bunch of container inside compose file

  1. up command documentation
  2. down command documentation
# Up command (With out build)
docker-compose -p nameproject -f /locate/your/docker/compose --no-build up -d
 
# Up command (With build)
docker-compose -p nameproject -f /locate/your/docker/compose --build up -d
 
# Up command (with specify target service)
docker-compose -p nameproject -f /locate/your/docker/compose up -d yourservice
 
# Down command
docker-compose -p nameproject -f /locate/your/docker/compose down 

Common options often use with compose, like

  • -p : set project name, represent your container name with service in compose file, example: next-application
  • -f : specify with compose file in use for execute with command

Note special Key in compose

Use host network to use driver of local interface,

Use when you want to call via DNS on different network with your eth interface

Documentation: Accessing Host Services from Docker Containers

services:
	application:
	    extra_hosts:
			- "host.docker.internal:host-gateway"

Select your network with external

networks:
  wkernet:
    driver: overlay
    external: true

Update compose

Documentation

Info

You can hand-on with compose via update the container inside stack to new version by trying pull and up again

If you have new version of images inside one of container, you can try to update that via

# You can specific services name or pull all of container
docker compose -f /file/compose -p name-stack pull <services-name>
 
# Try to restart containers in stack with new image
docker compose -f /file/compose -p name-stack up -d <services-name>