Docker Compose - Differences between stop, shutdown, start and start
Docker Compose has multiple commands that are similar but do completely different things. Some examples are the commands docker compose stop and docker compose down and the commands docker compose start and docker compose up.
This article will discuss their differences accordingly.
Difference between docker compose stop and docker compose down
Use docker-compose stop
The main function of the run docker compose stop
command is to stop the service of the running container. This command will stop our containers but will not necessarily delete them.
For example, if we do not specify a container name or ID, the following command will stop all containers:
$ docker compose stop
Output:
Going to stop file, web, test
Stopping file ... done
Stopping web ... done
Stopping test ... done
We can specify which container to stop by specifying the container name or ID:
$ docker compose stop file
Output:
Going to stop file
Stopping file ... done
Additionally, we can docker compose stop
specify a shutdown timeout at runtime. Docker will usually wait 10 seconds before stopping our container.
For example, if we know that our container may take more time when stopping, we may want to increase this timeout value as shown below.
$ docker compose stop file -t 60
Use docker compose down
On the other hand, the docker compose down command gives us an extra step in the process. This command will stop and remove the container and the services running in it; the removal includes the container and the network.
docker-compose downdocker stop <container name or id>
behaves similarly to and when executed sequentially docker <prune or rm>
. We can say that docker-compose down command is a shortcut for both composed commands.
Therefore, instead of running the following two commands:
$ docker compose stop file && docker compose rm -f
We can use docker compose down instead .
$ docker compose down file
We can boost this by appending the -v or --volumes flag to our docker-compose down command. This command will stop and remove the containers, their networks, and the volumes attached when it is executed.
By adding the above flags, we have combined the three commands into one.
$ docker compose down file -v
We can use the docker compose down command
not only on containers , but also on images. For example, we can run docker compose down --rmi <all or local>
the command to remove an image.
This command is similar to the docker rmi command when used in native Docker.
Difference between docker-compose start and docker-compose up
Use docker-compose start
As in our previous section, the commands docker compose start and docker compose up sound similar, but they are different in functionality. For example, the docker compose start command restarts a specific container that was previously stopped.
$ docker compose start file
Also, the above commands only work for created containers.
So, how can we directly start a container that has not been created? We can use the following command below.
Use docker-compose up
The docker-compose up command starts a new container based on the docker-compose.yml file. It is similar to running docker create and docker start when run sequentially with each other .
Since we are using a YAML file, we can create and start multiple containers with just one command.
docker compose up
Output:
Creating file
Creating web
Creating test
When we use docker compose up
, if there are any changes in the source YAML file, the container based on that YAML file will be stopped and recreated.
To avoid this, we can docker compose up
use the --no-recreate option during as shown below. In summary, if the container already exists, the command will not recreate it.
$ docker-compose up -d --no-recreate
Additionally, docker compose stop
just like , we can specify a timeout value.
$ docker-compose up -d -t 30
We can also say that this is the main counterpart of the command docker run when running and starting new containers in a vanilla Docker environment .
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Copy files from host to Docker container
Publish Date:2025/03/25 Views:126 Category:Docker
-
This article will discuss and demonstrate methods we can use to transfer files from the host to a running container in Docker. docker cp Copy the file from the host to the Docker container using docker cp The command is one of the simplest
Get the IP address of the Docker container
Publish Date:2025/03/25 Views:102 Category:Docker
-
This article demonstrates how to get the IP address of a Docker container. Connect to the Bridge network and get the IP address of the Docker container One of the big reasons why docker containers are so convenient is that we can easily con
Uninstalling Docker on macOS
Publish Date:2025/03/25 Views:95 Category:Docker
-
Recently, we have seen widespread adoption of Docker as the ultimate containerization platform. Because of this, setting up Docker on all platforms has been greatly simplified, including macOS and Windows. However, some users usually face p
Enter the Docker container's shell
Publish Date:2025/03/25 Views:98 Category:Docker
-
This article will demonstrate how to enter the Docker container shell using multiple methods. Use docker exec to enter the Docker container's shell We need to have a container up and running to use this command. We can check the status of t
Listing containers in Docker
Publish Date:2025/03/25 Views:122 Category:Docker
-
This article will discuss various commands for listing containers created in our system. This means we should create some containers beforehand for these commands to return values. List all running containers in Docker We will start by list
Mount the host directory into the Docker container
Publish Date:2025/03/25 Views:189 Category:Docker
-
Docker provides, among other features, tools to work with the host operating system and the container file system. One of these features is the ability to persist data in containers and share data between containers by mounting directories
Docker build command with multiple parameters
Publish Date:2025/03/25 Views:138 Category:Docker
-
docker build The command allows us to create a Docker image from a Dockerfile. It also allows us to build an image from a context that references a set of files located in a location specified by a PATH or URL. A Dockerfile, on the other ha
The difference between CMD and ENTRYPOINT in Docker
Publish Date:2025/03/25 Views:141 Category:Docker
-
Docker containers have become the standard when it comes to managing software and dependencies in different environments. When working with real-world applications, you need to create a docker file before building your application container
Use the Dockerfile to create a directory in the container using the Mkdir command
Publish Date:2025/03/25 Views:73 Category:Docker
-
Docker containers have become the de facto way to manage software and dependencies in different environments. When working with real-world applications, you will undoubtedly need to create a Dockerfile before you can build your application