Manipulating containers

Manipulating containers

List containers

Since we ran our container in the background, how do we know if our container is running or what other containers are running on our machine? Well, we can run the docker ps command. Just like on Linux to see a list of processes on your machine, we would run the ps command. In the same spirit, we can run the docker ps command which displays a list of containers running on our machine

List running containers

docker ps

Stop running container

docker stop romantic_taussig

Restart a container

docker restart romantic_taussig

Why did we restart instead of using start?

Notice that the container we just restarted has been started in detached mode and has port 80 exposed. Also, observe the status of the container is Up X seconds. When you restart a container, it starts with the same flags or commands that it was originally started with.

What if we do not want random names?

Standard practice is to name your containers for the simple reason that it is easier to identify what is running in the container and what application or service it is associated with.

To name a container, we just need to pass the --name flag to the docker run command.

docker run -d -p 5000:80 --name dotnet-app dotnet-docker

That’s better! We can now easily identify our container based on the name we want and not any random name.

Last updated