Installing Docker Compose on Debian 9
How to install Docker Compose and run a multi-container application on Debian 9.
Docker Compose is a tool for defining and running multi-container Docker applications. Services are configured in a YAML file, letting you spin up the entire environment with a single command.
Key features:
- multiple isolated environments on a single host;
- volume data is preserved when containers are recreated;
- only changed containers are recreated;
- variables can be passed between environments.
Before installing Docker Compose, make sure Docker is already installed — see Installing Docker on Debian 9.
Installation
Download Docker Compose from the GitHub repository. Check the latest release and update the version number in the command if needed:
sudo curl -L https://github.com/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Set the execute permission:
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
Expected output:
docker-compose version 1.25.5, build 8a1c60f6
Running a container with Docker Compose
Create a directory for the test project and navigate into it:
mkdir hello-world
cd hello-world
Create a docker-compose.yml file:
nano docker-compose.yml
Add the following content and save the file:
my-test:
image: hello-world
The first line defines part of the container name, the second specifies the image. When docker-compose up runs, Docker looks for the image locally first, then pulls it from Docker Hub if not found.
Check the list of local images:
docker images
If no images are present, only column headers will appear:
REPOSITORY TAG IMAGE ID CREATED SIZE
Start the container:
docker-compose up
Docker will pull the image, create the container, and run it:
Creating hello-world_my-test_1 ... done
Attaching to hello-world_my-test_1
my-test_1 |
my-test_1 | Hello from Docker!
my-test_1 | This message shows that your installation appears to be working correctly.
...
hello-world_my-test_1 exited with code 0
The container stops once the program finishes. It won't appear in the list of active processes:
docker ps
To view all containers including stopped ones, use the -a flag:
docker ps -a
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
4e8158d490ac hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago hello-world_my-test_1
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!