Lenna  Kihn

Lenna Kihn

1669194221

Top 20 Docker Commands You Should Know

In this article, we will learn together about the top 20 Docker commands you should know. In the realm of software engineering, docker has a significant part to play. It has been extensively used to develop, test, and manage the environment in the software industry. The portability feature makes it easy for developers to collaborate on projects even from remote locations across the globe. However, the world of docker can be a bit overwhelming when using its commands. Docker documentation is extensive, with over a billion commands to learn, to streamline software development. In this article, we will discuss the most popular and widely used docker commands that will ease the process of software development for you. You can bookmark this guide to use it as a reference later on.  

What is Docker?

Docker is a free and open platform that offers an immersive experience to the developers working on various aspects of software development. It is a containerization platform that allows developers to package code into various deployable units called containers. Docker Engine is the software that oversees the hosting of the containers. The subset of the Moby Project, Docker, helps developers build, run, and deploy containers on the server and the cloud. The container contains a builder, engine, and orchestrator to deliver a seamless application that runs in any environment. 

Docker is preferred by developers working on individual projects as it offers a lightweight environment for testing. It comes with both free and premium tiers. Docker was initially released in 2013 and is written in Go. 

Also Read: Know the difference between Docker vs Kubernetes

Top 20 Docker Commands

We have enlisted 20 docker commands to help you navigate through the docker engine seamlessly and get most of your work done. Let us get started. 

  • Docker version
  • Docker search 
  • Docker pull
  • Docker run 
  • Docker ps
  • Docker stop 
  • Docker restart 
  • Docker kill
  • Docker exec 
  • Docker login
  • Docker commit 
  • Docker push 
  • Docker network 
  • Docker history 
  • Docker rmi 
  • Docker ps -a
  • Docker copy
  • Docker logs   
  • Docker volume 
  • Docker logout 
  1. Docker version

We usually start by finding the installed version of docker that we are working on. Here is how to find it –

greatlearning@greatlearning:/home/greatlearning$ docker --version
Docker version 18.09.6, build 481bc77
  1. Docker search 

The “docker search” command searches for specific images through the Docker hub. This command returns the specific information, including image name, description, automated, official stars, etc. Here is how to use it – 

docker search MySQL

You can use the Docker Hub website to search through the GUI-based option.

  1. Docker pull

As the name suggests, this command pulls a specific image from the Docker Hub. All you have to do is use the command ‘docker pull’ along with the name of the image. Here is an example of pulling an image without using the tag. 

docker pull --platform Linux/x86_64 MySQL
Here is an example that demonstrates how to pull an Apache HTTP server image from the Docker repository using the tag -
Using default tag: latest
latest: Pulling from library/httpd
f5d23c7fed46: Pull complete
b083c5fd185b: Pull complete
bf5100a89e78: Pull complete
98f47fcaa52f: Pull complete
622a9dd8cfed: Pull complete
Digest: sha256:8bd76c050761610773b484e411612a31f299dbf7273763103edbda82acd73642
Status: Downloaded newer image for httpd: latest
greatlearning@greatlearning:/home/greatlearning$

The tags are used to identify the images inside the Docker hub. If you do not specify a tag, it will use the ‘: latest’ tag by default. 

We can use the command ‘-all-tags’ to pull all the images from the repository for multiple images. 

  1. Docker run 

This command is used to create a container from an image. Here is how to do it –

docker run --env MYSQL_ROOT_PASSWORD=my-secret-pw --detach mysql

The ‘–detach’ option runs the container, and the ‘–env’ option is used to set the mandatory variable. If you do not use the ‘–name’ option, the docker will randomly assign a name to the container.

  1. Docker ps

This command is used to list all the running containers in the background. Here is how to do it –

docker ps --all
  1. Docker stop 

The ‘docker stop’ command stops a container using the container name or its id. Here is how to do it –

docker stop f8c52bedeecc
  1. Docker restart 

This command is used to restart the stopped container. It is recommended to use this after rebooting the system. Here is how to do it –

greatlearning@greatlearning:/home/greatlearning$
docker restart f8c52bedeecc
  1. Docker kill

This command is used to stop the container immediately by killing its execution. While the ‘docker stop’ command helps shut down the container in its own time, the ‘docker kill’ command stops it at once. Here is to use it –

greatlearning@greatlearning:/home/greatlearning$
docker kill 09ca6feb6efc
To check whether the container is stopped or killed, use the following command -
greatlearning@greatlearning:/home/greatlearning$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

  1. Docker exec 

This command is used to access the container that is running. Here is how to use it –

docker exec -it test_db bash
mysql -uroot -pmy-secret-pw
SHOW DATABASES;

You have to either provide the name or the id of the container, which is ‘test_db’ in this case. The ‘-i’ and ‘-t’ options are used to access the interactive mode. 

  1. Docker login

This command helps you to log into your docker hub. As you try to log in, you will be asked to give your docker hub credentials. 

greatlearning@greatlearning:/home/greatlearning$ docker login
Login with your Docker ID to push and pull images from Docker Hub. Suppose you don’t have a Docker ID, head over to https://hub.docker.com to create one.
Username: greatlearning
Password:
Configure a credential helper to remove this warning. See: https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
  1. Docker commit 

This command is used to create or save an image of the edited container on the local system. 

Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$
docker commit 09ca6feb6efc greatlearning/httpd_image
sha256:d1933506f4c1686ab1a1ec601b1a03a17b41decbc21d8acd893db090a09bb31c
Here, ‘greatlearning’ is the username and ‘httpd_image’ is the image name of the edited container. 
  1. Docker push 

This command helps push or upload a docker image on the repository or the docker hub. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker push greatlearning/httpd_image
The push refers to the repository [docker.io/greatlearning/httpd_image]
734d9104a6a2: Pushed
635721fc6973: Mounted from library/httpd
bea448567d6c: Mounted from library/httpd
bfaa5f9c3b51: Mounted from library/httpd
9d542ac296cc: Mounted from library/httpd
d8a33133e477: Mounted from library/httpd
latest: 
digest: sha256:3904662761df9d76ef04ddfa5cfab764b85e3eedaf10071cfbe2bf77254679ac size: 1574
  1. Docker network 

The ‘docker network’ command is used to know the details of the list of networks in the cluster. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
85083e755f04        bridge              bridge              local
f51d1f2379e0        host                host                local
5e5d9a154c00        none                null                local
Apart from this, you can also use the following docker network commands to manage networks -
Connect  - to connect a container to a network
Disconnect - to disconnect a container from a network
Create  - to create a network
Ls - to list all networks
Inspect - to display detailed information on one or more networks
prune - to remove all unused networks
rm - to remove one or more networks
Docker history 
This command is used to check the history of a docker image. The image name has to be mentioned while using the command. Here is how to use it -
greatlearning@greatlearning:/home/greatlearning$ docker history httpd
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
ee39f68eb241        3 days ago          /bin/sh -c #(nop)  CMD ["httpd-foreground"]     0B
<missing>           3 days ago          /bin/sh -c #(nop)  EXPOSE 80                    0B
<missing>           3 days ago          /bin/sh -c #(nop) COPY file:c432ff61c4993ecd…   138B
<missing>           2 days ago          /bin/sh -c set -eux;   savedAptMark="$(apt-m…   49.1MB
<missing>           2 days ago          /bin/sh -c #(nop)  ENV HTTPD_PATCHES=           0B
<missing>           2 days ago          /bin/sh -c #(nop)  ENV HTTPD_SHA256=b4ca9d05…   0B
<missing>           2 days ago          /bin/sh -c #(nop)  ENV HTTPD_VERSION=2.4.39     0B
<missing>           2 days ago          /bin/sh -c set -eux;  apt-get update;  apt-g…   35.4MB
<missing>           5 days ago          /bin/sh -c #(nop) WORKDIR /usr/local/apache2    0B
<missing>           5 days ago          /bin/sh -c mkdir -p "$HTTPD_PREFIX"  && chow…   0B
<missing>           5 days ago          /bin/sh -c #(nop)  ENV PATH=/usr/local/apach…   0B
<missing>           5 days ago          /bin/sh -c #(nop)  ENV HTTPD_PREFIX=/usr/loc…   0B
<missing>           4 days ago          /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>           4 days ago          /bin/sh -c #(nop) ADD file:71ac26257198ecf6a…   69.2MB
  1. Docker rmi 

This command is used to free up some disk space. The image id is used to remove the image while using this command.

docker rmi eb0e825dc3cf
  1. Docker ps -a

This command is used to know the details of all the running, stopped, or exited containers. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker ps -a
CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS                     PORTS                                                                                                                                NAMES
09ca6feb6efc        httpd                            "httpd-foreground"       51 seconds ago      Up 49 seconds              80/tcp                                                                                                                               sane_trell
2f6fb3381078        sequenceiq/hadoop-docker:2.7.0   "/etc/bootstrap.sh -d"   2 weeks ago         Exited (137) 9 days ago                                                                                                                                         better_naman
9f397feb3a46        sequenceiq/hadoop-docker:2.7.0   "/etc/bootstrap.sh -…"   2 weeks ago         Exited (255) 2 weeks ago   2122/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp   determined_sarah
9b6343d3b5a0        hello-world                      "/hello"                 2 weeks ago         Exited (0) 2 weeks ago                                                                                                                                          mega_steven
  1. Docker copy

This command copies a file from docker to the local system. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ sudo docker cp 09ca4feb7tfc:/usr/local/apache2/logs/httpd.pid /home/greatlearning/
[sudo] password for greatlearning:
In the above example, we used the docker container with id 09ca4feb7tfc to copy the file ‘http.pid.’ To check whether the file is copied or not, run this command -
greatlearning@greatlearning:/home/greatlearning$ ls
Desktop  Documents  example  examples.desktop  httpd.pid  nginx_new.yml  nginx.yml
  1. Docker logs   

This command is used to check the logs of all the docker containers with the corresponding contained id mentioned in the command. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker logs 09ca6feb6efc
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
[Mon Jul 16 14:01:55.400472 2019] [mpm_event:notice] [pid 1:tid 140299791516800] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations
[Mon Jul 16 14:01:55.400615 2019] [core:notice] [pid 1:tid 140299791516800] AH00094: Command line: 'httpd -D FOREGROUND'
[Mon Jul 16 14:08:36.798229 2019] [mpm_event:notice] [pid 1:tid 140299791516800] AH00491: caught SIGTERM, shutting down
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
[Mon Jul 15 14:08:38.259870 2019] [mpm_event:notice] [pid 1:tid 139974087980160] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations
[Mon Jul 15 14:08:38.260007 2019] [core:notice] [pid 1:tid 139974087980160] AH00094: Command line: 'httpd -D FOREGROUND'
[Mon Jul 15 14:09:01.540647 2019] [mpm_event:notice] [pid 1:tid 139974087980160] AH00491: caught SIGTERM, shutting down
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
[Mon Jul 16 14:10:43.782606 2019] [mpm_event:notice] [pid 1:tid 140281554879616] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations
[Mon Jul 16 14:10:43.782737 2019] [core:notice] [pid 1:tid 140281554879616] AH00094: Command line: 'httpd -D FOREGROUND'
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2. Set the ‘ServerName’ directive globally to suppress this message
[Mon Jul 16 14:14:08.270906 2019] [mpm_event:notice] [pid 1:tid 140595254346880] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations
[Mon Jul 16 14:14:08.272628 2019] [core:notice] [pid 1:tid 140595254346880] AH00094: Command line: 'httpd -D FOREGROUND'
  1. Docker volume 

This command creates a volume so that the docker container can use it to store data. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker volume create
7e7bc886f69bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0
To check whether this command created the volume or not, run the following command -
greatlearning@greatlearning:/home/greatlearning$ docker volume ls
DRIVER              VOLUME NAME
local               7e7bc886f69bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0
  1. Docker logout 

This command will log you out of the docker hub. Here is how to use it –

greatlearning@greatlearning:/home/greatlearning$ docker logout
Removing login credentials for https://index.docker.io/v1/

Conclusion

You can try out the docker commands in your lab environment to practice them for source development. We hope these 20 docker commands will help you get started with docker and learn to perform basic functions without getting overwhelmed. Get your hands on the free Docker for Windows and brush up your Docker skills.


Original article source at: https://www.mygreatlearning.com

#docker 

What is GEEK

Buddha Community

Top 20 Docker Commands You Should Know
Ray  Patel

Ray Patel

1619571780

Top 20 Most Useful Python Modules or Packages

 March 25, 2021  Deepak@321  0 Comments

Welcome to my blog, In this article, we will learn the top 20 most useful python modules or packages and these modules every Python developer should know.

Hello everybody and welcome back so in this article I’m going to be sharing with you 20 Python modules you need to know. Now I’ve split these python modules into four different categories to make little bit easier for us and the categories are:

  1. Web Development
  2. Data Science
  3. Machine Learning
  4. AI and graphical user interfaces.

Near the end of the article, I also share my personal favorite Python module so make sure you stay tuned to see what that is also make sure to share with me in the comments down below your favorite Python module.

#python #packages or libraries #python 20 modules #python 20 most usefull modules #python intersting modules #top 20 python libraries #top 20 python modules #top 20 python packages

August  Murray

August Murray

1615008840

Top 24 Docker Commands Explained with Examples

In my previous blog post, I have explained in detail how you can Install Docker and Docker-compose on Ubuntu

In this guide, I have explained the Top 24 Docker Commands with examples.

Make sure you have sudo or root privileges to the system.

Docker Commands

  1. The command to check the version of Docker installed.
  2. To look/search for available docker images from the Docker registry.
  3. To pull docker images from the Docker registry.
  4. Listing all the docker images
  5. Creating / Running docker container from Docker image.
  6. To list the actively running docker containers.
  7. To list all the docker containers
  8. To stop a Container
  9. To start a Container
  10. To restart a Docker container
  11. To login to running Docker container
  12. To delete the stopped Docker containers
  13. To delete Docker images from the Local system
  14. To check logs of a running Docker container
  15. Killing docker containers
  16. Log in to Docker Hub registry (hub.docker.com)
  17. Removing docker hub registry login from the system.
  18. Check active resource usage by each containers
  19. Rename a Docker container
  20. To display system wide information of Docker
  21. Inspecting a Docker container
  22. Building docker images from Docker file
  23. Creating new docker images from a Container
  24. Pushing Docker images from Local to Docker registry.

#docker #docker-command #containers #docker-compose #docker-image

Alex Tyler

Alex Tyler

1601280276

Top 5 Important Docker Commands You Should Know

What are a docker image and docker container?

As per the official website, a Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

And docker container is an instance of the docker image, docker container is a docker image brought to life.

Breakdown of docker commands syntax:

Every docker command can be broken down into 3 parts :

1\. Keyword 'docker'
2\. Main task (start, stop, build, etc).
3\. Options (port, tty, interactive volumes, etc).
4\. Reference to image or container with all the property flags.

Every docker command starts with the ‘docker’ keyword.

2nd part of the command represents the main task which we want to execute on a docker image or on a docker container (like run for running a container, build for building an image, etc).

3rd part includes the extra options like the port number mapping (-p ), interactive communication (-i), tty (-t), volumes (-v), etc. A flag with a single dash (-) is the shortcut for the full name flag like (-p for — port) and a double dash is used for the full name.

4th part is the reference to an image or a container (like the container-id, image-name, image-id, etc).

#docker-image #dockerfiles #docker-command #containers #docker

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Henry Short

Henry Short

1580104680

List all containers in Docker(Docker command)

We can get a list of all containers in docker using docker container list or docker ps commands.

List Docker Containers

To list down docker containers we can use below two commands

  • docker container list
  • docker ps

docker container ls command introduced in docker 1.13 version. In older versions we have to use docker ps command.

List all Containers in docker, using docker ls command

The below command returns a list of all containers in docker.

docker container list -all

or

docker container ls -all

List all containers in docker, using docker ps command

In older version of docker we can use docker ps command to list all containers in docker.

$ docker ps -all

or

$ docker ps -a

List all Running docker containers

The default docker container ls command shows all running docker containers.

$ docker container list

or

$ docker container ls

or

To get list of all running docker containers use the below command

$ docker ps

List all stopped docker containers command

To get list of all stopped containers in docker use the below commands

$ docker container list -f "status=exited"

or

$ docker container ls -f "status=exited"

or you can use docker ps command

$ docker ps -f "status=exited"

List all latest created docker containers

To list out all latest created containers in docker use the below command.

$ docker container list --latest

Show n last created docker containers

To display n last created containers in docker use the below command.

$ docker container list --last=n

#docker #docker-container #docker-command