Docker

Start a stopped docker container and log-in into a running container

Start a stopped docker container

Today we are going to understand that what to do when a docker container is stopped, and some of the reasons why a container is stopped are “it may be done intentionally” or “it may be due to some fault in the system“.

Make sure you know -> What docker is and how it works?

To begin with, we need to check whether there are any stopped containers in our list or not.

checking any stopped docker containers

sudo docker container ls -a

From the image above, it can be worth noting that the container named as “container1” having a “container id = f446a7b999d7” is stopped about a minute ago.

Now, at this moment we want to log-in into the “container1“, but when we try to do the same it shows us the following error:

you cannot attach a stopped container, start it first.

Question: So, how to remove the above error?

Answer: The error is thrown by docker daemon because we are trying to log-in into a stopped container, which is impossible so in order to remove this error, we need to run the container first.

start a stopped docker container

sudo docker container start container1

Now, after starting the container, we need to crosscheck by running the following command again.

From above, you can see that the container which is stopped earlier is now in the running state again.

log-in into a running container

Question: What if we are logged out of a docker container and we want to log-in back again?

Answer: First of all, it can be only done if the container is in running state and if not, then we have to start it first and then run the following command for logging in.

log in into a running container

Conclusion

We now have knowledge about starting a docker container and regarding logging in into a container, moreover do make sure that you know “how to install docker on centos 7” because without having docker on your machine it will be very difficult for you to learn it.

Comment here