Up/down#
This page provides an overview of the options and features you can utilize when running or stopping projects in Docker Compose.
Specify service#
You can specify an exact service to run with docker compose up
by providing the service name(s) after up
. Only the specified services will be started.
The following cell defines compose.yml
with three services, each of which outputs its name during execution.
cat << EOF > /tmp/compose.yml
services:
linux1:
image: alpine
command: sh -c "echo message_linux1"
linux2:
image: alpine
command: sh -c "echo message_linux2"
linux3:
image: alpine
command: sh -c "echo message_linux3"
EOF
The following cell executes up
without specification of the services that have to be runned. As result - invocations from all services (invocations are highlited in the output).
docker compose -f /tmp/compose.yml up
docker compose -f /tmp/compose.yml down &> /dev/null
?25l[+] Running 0/0
⠋ Network tmp_default Creating 0.1s
?25h?25l[+] Running 1/1
✔ Network tmp_default Created 0.1s
⠋ Container tmp-linux3-1 Creating 0.1s
⠋ Container tmp-linux2-1 Creating 0.1s
⠋ Container tmp-linux1-1 Creating 0.1s
?25h?25l[+] Running 4/4
✔ Network tmp_default Created 0.1s
✔ Container tmp-linux3-1 Created 0.1s
✔ Container tmp-linux2-1 Created 0.1s
✔ Container tmp-linux1-1 Created 0.1s
?25hAttaching to linux1-1, linux2-1, linux3-1
linux1-1 | message_linux1
linux2-1 | message_linux2
linux3-1 | message_linux3
linux1-1 exited with code 0
linux3-1 exited with code 0
linux2-1 exited with code 0
But if you specify only the linux1
and linux3
services, there will be output only from those two.
docker compose -f /tmp/compose.yml up linux1 linux3
docker compose -f /tmp/compose.yml down &> /dev/null
?25l[+] Running 0/0
⠋ Network tmp_default Creating 0.1s
?25h?25l[+] Running 1/1
✔ Network tmp_default Created 0.1s
⠋ Container tmp-linux1-1 Creating 0.1s
⠋ Container tmp-linux3-1 Creating 0.1s
?25h?25l[+] Running 3/3
✔ Network tmp_default Created 0.1s
✔ Container tmp-linux1-1 Created 0.1s
✔ Container tmp-linux3-1 Created 0.1s
?25hAttaching to linux1-1, linux3-1
linux3-1 | message_linux3
linux1-1 | message_linux1
linux3-1 exited with code 0
linux1-1 exited with code 0
linux2
wasn’t stated.