Understand the purpose of docker desktop start
In this step, we will understand the purpose of the docker start
command. The docker start
command is used to start one or more stopped containers. When you stop a container using docker stop
, its state is saved, and you can resume it later using docker start
. This is different from docker run
, which creates a new container from an image and then starts it.
First, let's create a simple container that we can stop and then start. We will use the ubuntu
image and run a command that keeps the container running for a short period.
docker run -d --name my-ubuntu ubuntu sleep 60
This command runs an Ubuntu container in detached mode (-d
), names it my-ubuntu
, and executes the sleep 60
command inside the container. The sleep 60
command will keep the container running for 60 seconds.
Now, let's check the status of the container using docker ps
.
docker ps
You should see the my-ubuntu
container listed with a status of Up
.
Next, we will stop the container using the docker stop
command.
docker stop my-ubuntu
This command sends a stop signal to the my-ubuntu
container.
Now, let's check the status of the container again using docker ps
.
docker ps
You should see that the my-ubuntu
container is no longer listed in the output of docker ps
(which shows only running containers). To see all containers, including stopped ones, you can use docker ps -a
.
docker ps -a
You should now see my-ubuntu
listed with a status of Exited
. This confirms that the container has been stopped.
Finally, we will use the docker start
command to start the stopped container.
docker start my-ubuntu
This command starts the my-ubuntu
container.
Let's check the status of the container one last time using docker ps
.
docker ps
You should see the my-ubuntu
container listed again with a status of Up
. This demonstrates that docker start
successfully resumed the previously stopped container.
In summary, docker start
is used to resume a stopped container, preserving its state, while docker run
creates and starts a new container.