So I have been using Docker on & off for quite some time now, so when I started using Docker in 2016, I learned about it a bit & I learned about the Docker commands & I was quite comfortable with it. Then my role got changed & I was not using Docker anymore at all. Forward to 2018, I started using it again, but some things were changed with the way commands in Docker worked. Whenever I would reference a document, the commands were a bit changed, they were somewhat different.
Though their corresponding old commands would still work but Docker did introduce some changes & i believe those were welcomed changes. But it did create some confusion for me for a short while, some others might be confused with the old commands and new commands. I know most will say that these are not new commands as the change happened quite some time ago but still I thought of writing this article.
Recommended Read: The (in)complete Guide To DOCKER FOR LINUX
Also Read: How to manage network in Ubuntu 18.04 – Netplan Command
This article will work as a reference for old Docker commands & their replacement, the new & improved Docker commands. So earlier commands would be called like,
# docker command options
For example,
# docker run image-id
Now they are mentioned like.
# docker command sub-command option
For example,
# docker container run image-id
Now we will discuss some other important commands that got an upgrade & will also discuss some newly introduced commands in Docker.
The way this will work is, I will first mention the old command and then will mention the new command followed by a brief about the command, like,
# OLD_COMMAND --- NEW_COMMAND --- Brief introduction of command
So let’s get going.
Docker Commands
-
docker ps --- docker container ps --- provides list of all running containers.
-
docker run --- docker container run --- starts up a new container.
-
docker stop --- docker container stop --- stops a docker container.
-
docker logs --- docker container logs --- check the logs of the running container.
-
docker rm --- docker container rm --- deletes a running container.
-
docker run -it bash --- docker container run -it bash --- change the entry point to bash, create a terminal session for a new container.
-
docker exec -it bash --- docker container exec -it bash --- starts a shell session for running container.
-
docker port --- docker container port --- Show the mapped ports for the containers.
-
docker top --- docker container top --- provides all the processes running inside a container.
-
docker inspect --- docker container inspect --- get detailed information about an object.
-
docker stats --- docker container stats --- provides a live data stream of the running containers.
Then there are some new commands introduced as well related to Docker Networking.
Docker Networking Commands
-
docker network ls --- show the list networks created for docker.
-
docker network inspect --- show detailed information for one or more networks.
-
docker network create --- creates a new network.
-
docker network connect --- connect a container to a network.
-
docker network disconnect --- disconnect a network from a container.
-
docker network prune --- removes all unused networks.
I have tried to cover all the important commands that we use, but in case I have missed something (which I am sure I have ) or have added something wrong or you have any query or questions regarding this tutorial, then you can write to us using the comment box below.