Docker Chapter: 1 Basic Commands

Please go to this link to install docker or

Docker Commands

  1. The command to check the version of Docker installed.

2. To look/search for available docker images from the Docker registry.

nginx is the image name we are searching for, from the official docker registry. The image will have a basic nginx configuration.

3. To pull docker images from the Docker registry.

After searching for an image, If it is available you can pull it from the docker registry.

The above command will pull the nginx — docker image from the docker registry to the local system/server.

4. Listing all the docker images

The above command will list all the docker images stored locally on the system.

5. Creating / Running docker container from a Docker image.

After pulling the image from the docker registry, We can run a docker container from that image.

-d (detached mode)- It will run the docker container in the background.

-it (interactive mode) — means You can execute commands inside the docker container while it is running.

6. To list the actively running docker containers.

The above command will list all the containers which are currently running.

7. To list all the docker containers

The above command will list all the actively running as well as the containers in the stopped state.

8. To stop a Container

If you want to stop a running docker container,

9. To start a Container

To start a container that is in a stopped state.

10. To restart a Docker container

The command to restart the running docker container.

11. To login to running Docker container

If you want to execute some bash commands or make configuration changes within the docker container, You can access it using the below command.

12. To delete the stopped Docker containers

The above command will delete the docker container which is in the stopped state from the system.

13. To delete Docker images from the Local system

If you’ are deleting an image, But If there are containers running with those images, You will get the below error.

If you’re not running containers from the docker image on the local system, You should be able to delete it.

14. To check logs of a running Docker container

-f (–follow) — To follow docker output logs or tail continuously

15. Killing docker containers

The docker stop command will give some time for the container to shut down gracefully, But sometimes It takes so much of time for the container to go to stopped state, In this case, we will run docker kill to stop it immediately.

16. Log in to Docker Hub registry (hub.docker.com)

docker login is a command which is used to login to the docker hub registry from the local system.

Once logged in you can push or pull images from local systems to private docker repository.

Before running the docker login command, Make sure you have the credentials in place.

It will ask for username and password, Once validated, You should get a message as Login Succeeded

17. Removing the Docker hub registry login from the system.

In the previous command, We used a docker login to login to the docker hub registry on the local system.

Run the below command, If you want to remove the docker login from the system.

And If you check /root/.docker/config.json file, You can see that the auth is removed from the system.

18. Check active resource usage by each container

The above command displays the active Memory and CPU usage of all the containers on the system.

19. Rename a Docker container

When you pull an image from the Docker registry and run a container out of it, It will automatically set a name for a container.

If you want to change the name of the container at any time, Run the below command.

From the below image, You can see the name of the container is abhi_demo

To change the name of the container,

With the help of above command, We have changed the name of the container from abhi_demo to nodejs

20. To display system-wide information of Docker

The above command will display information such as the number of total containers, Container running, containers stopped the number of images available on the system, kernel version, plugins, volumes, etc.

21. Inspecting a Docker container

The docker inspects command will list the complete information of the docker container in JSON format.

You can also truncate the output and check based on what needs to be verified. For example, You can get the information only about the networking part (IP address) of the container as shown below.

22. Building docker images from Docker file

The docker build command builds docker images from a Dockerfile.

. represents the directory where Dockerfile is present.

23. Creating new docker images from a Container

If you have made any changes to the containers, You can create a new docker image from that docker using the below command.

username — The username of the hub.docker.com

24. Pushing Docker images from Local to Docker registry.

--

--

DevOps/Cloud | 2x AWS Certified | Terraform | Gitlab

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store