JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Docker >

Docker Compose - Differences between stop, shutdown, start and start

Author:JIYIK Last Updated:2025/03/25 Views:

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 stopcommand 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 stopspecify 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 upuse 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 stopjust 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.

Article URL:

Related Articles

Docker deploys nginx php application

Publish Date:2025/03/26 Views:131 Category:Docker

I'm learning docker recently. I'm learning by building an nginx+php development environment example. Here I record the build process. First, give a docker-compose.yml deployment configuration file version: '3' services: nginx: container_nam

How to use Docker to image a Node.js web application

Publish Date:2025/03/26 Views:107 Category:Docker

Docker is a containerization platform that simplifies the packaging and execution of applications. Containers run as independent processes with their own file systems, but share the kernel of their host machine. Docker has attracted much at

Start a Bash terminal in a new Docker container

Publish Date:2025/03/26 Views:97 Category:Docker

Docker containers are a standard unit for packaging all the dependencies of an application, allowing us to easily run them in any environment. Containers have become very popular recently, and most developers now rely heavily on containers

Passing environment variables to containers in Docker

Publish Date:2025/03/26 Views:125 Category:Docker

This article will introduce how to pass environment variables to containers in Docker. Passing environment variables to containers in Docker using the -e and tags -env We will first see how to create environment variables and pass them to t

Install Docker using Homebrew

Publish Date:2025/03/26 Views:202 Category:Docker

There is no doubt that Docker containers have revolutionized the way we develop and deploy applications. They provide developers with the ability to package applications and dependencies in an isolated environment. Recently, we've seen wide

Enforce clean build of images in Docker

Publish Date:2025/03/26 Views:88 Category:Docker

This article discusses and demonstrates how to enforce clean builds of images in Docker. Building images in Docker We will use a simple Flask application to demonstrate this concept. my-app Create a app.py simple application named in the ho

Running a Docker instance from a Dockerfile

Publish Date:2025/03/26 Views:140 Category:Docker

Docker containers have undoubtedly become the standard unit for managing software and dependencies in different environments. When using real applications, you must create a docker file before building the container image of the application

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial