table of Contents
- Introduction
- What is Docker?
- Top 20 Docker Commands
Introduction
Are you new to Docker and wondering how to manage Docker containers efficiently? Don't worry, docker commands can help you with that! Docker is a popular platform that allows developers to package their applications, dependencies, and configurations in containers that run seamlessly in different environments.
With Docker commands, you can easily create, run, stop, delete, and manage Docker containers. These commands help you automate and simplify the process of developing and managing your applications in a containerized environment.
Let's take a look at some of the most commonly used Docker commands that can help you manage Docker containers efficiently.
docker execution
– This command is used to start a new Docker container from an image.dockworker p.s.
- This command is used to list all running Docker containers.docker stops
– This command is used to stop a running container.dockworker rm
– This command is used to remove a Docker container.pier images
- This command is used to display all Docker images currently available on your system.dock worker pulls
– This command is used to download a Docker image from a registry.port officer
– This command is used to run a command in a running container.docker build
- This command is used to manage multi-container Docker applications.
These commands make it easy to manage Docker containers, images, and applications. Whether you're a newbie or an experienced Docker user, knowing these commands can help you improve your Docker skills.
Watch these lessons andlearn docker for free.
What is Docker?
Docker is a free and open platform that provides an immersive experience for developers working on various aspects of software development. It is a containerization platform that allows developers to package code into multiple deployable units called containers. Docker Engine is the software that oversees container hosting. A subset of the Moby project, Docker helps developers build, run, and deploy containers on the server and in the cloud. The container includes a builder, engine, and orchestrator to provide a seamless application that runs in any environment.
Developers working on individual projects prefer Docker as it provides a lightweight testing environment. It comes with free and premium levels. Docker was first released in 2013 and is written in Go.
Also read: Learn the difference betweenDocker versus Kubernetes
Top 20 Docker Commands
We've rounded up 20 docker commands to help you seamlessly navigate the docker engine and get the most of your work done. Let us begin.
- dockable version
- Search docker
- Docker tira
- docker-execute
- Dokwerker p.d.
- docker stops
- Restart docker
- kill docker
- docker executive
- Docker login
- Docker compromise
- Docker push
- Red acoplable
- dockable history
- rmi docker
- ps-a docker
- dockable copy
- docker records
- docker volume
- Log out of docker
Learn more with these free courses
Roadmap to becoming a full stack developermid-tier dockerMonitor in Docker
- dockable version
Usually we start by finding the installed version of docker we are working on. This is how to find it:
greatlearning@greatlearning:/home/greatlearning$ docker --versionDocker version 18.09.6, build 481bc77
- Search docker
The "docker search" command searches for specific images through the Docker hub. This command returns the specific information such as image name, description, automatic official stars, etc. Here's how to use it:
Docker consulta MySQL
You can use the Docker Hub website to search through the GUI-based option.
- Docker tira
As the name suggests, this command pulls a specific image from Docker Hub. All you have to do is use the 'docker pull' command together with the image name. Here is an example of taking an image without using the tag.
docker pull --platform Linux/x86_64 MySQL Este es un ejemplo que muestra cómo extraer una imagen del servidor Apache HTTP del repositorio de Docker usando la etiqueta -Use default tag: latest: Pull from library/httpdf5d23c7fed46: Pull complete 7fcaa52f : Pull complete622a9dd8cfed : Pull CompleteDigest: sha256:8bd76c050761610773b484e411612a31f299dbf7273763103edbda82acd73642Estado: http://downloadedleargrelearning@ εκμήματηση$
Tags are used to identify images in the Docker hub. If you don't specify a tag, the ':latest' tag will be used by default.
We can use the '-all-tags' command to get all images from the multi-image repository.
- docker-execute
This command is used to create a container from an image. Here's how to do it -
ventana acoplable ejecutar --env MYSQL_ROOT_PASSWORD=my-secret-pw --deach mysql
The “–unlink” option runs the container and the “–env” option is used to set the mandatory variable. If you don't use the '–name' option, docker will randomly assign a name to the container.
- Dokwerker p.d.
This command is used to list all the containers that are running in the background. Here's how to do it -
docker ps --all
- docker stops
The 'docker stop' command stops a container using the container name or its ID. Here's how to do it -
docker stop f8c52bedeecc
- Restart docker
This command is used to restart the stopped container. It is recommended to use it after rebooting the system. Here's how to do it -
greatlearning@greatlearning:/home/greatlearning$docker herstart f8c52bedeecc
- kill docker
This command is used to stop the container immediately by stopping its execution. While the 'docker stop' command helps to shut down the container in time, the 'docker kill' command stops it immediately. Here it is to use it -
greatlearning@greatlearning:/home/greatlearning$docker kill 09ca6feb6efcUse the following command to check if the container is stopped or killed -greatlearning@greatlearning:/home/greatlearning$ docker psCONTAINER IMAGE CREATED NAME STATE
- docker executive
This command is used to access the running container. Here's how to use it:
docker exec -it test_db bashmysql -uroot -pmy-secret-pwTOON DATBASES;
You must specify the name or ID of the container, in this case "test_db". The '-i' and '-t' options are used to access interactive mode.
- Docker login
This command will help you connect to your docker hub. When attempting to connect, you will be prompted for your docker hub credentials.
greatlearning@greatlearning:/home/greatlearning$ docker login Log in with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, go to https://hub.docker.com to create one. Username: greatlearning Password: Set up a credential wizard to remove this warning. See: https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin successful
- Docker compromise
This command is used to create or save an image of the edited container on the local system.
Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$docker commit 09ca6feb6efc greatlearning/httpd_imagesha256:d1933506f4c1686ab1a1ec601b1a03a17b41decbc21d8bbbat30909 here is username90bcd909 and 'httpd_image ' is the name of the edited owner image.
- Docker push
This command helps to push or upload a docker image to the docker repository or hub. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ docker push greatlearning/httpd_imagePush apunta al repositorio [docker.io/greatlearning/httpd_image]734d9104a6a2: Pushed635721fc6973 httpdbea from library6973: Linked from library74bd64/8. f9c3b51: Montado desde la biblioteca/http d9d 542ac296cc: Montado desde la biblioteca/httpdd8a33133e477: Montado desde la biblioteca/httpdlatest: resumen: sha256:3904662761df9d76ef04ddfa5cfab764b85e3eedaf1026175c size:24b175c
- Red acoplable
The 'docker-network' command is used to get the details of the list of networks in the cluster. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ network docker lsNETWORK NAME DRIVER NAME SCOPE85083e755f04 bridge bridge localf51d1f2379e0 host host local5e5d9a154c00 none null localIn addition to this, you can also create a network -Dickers to manage the following connection commands - to disconnect a container from a networkCreate - to create networks Ls - to list all networks Inspect - to view detailed information about one or more networks sprune - to remove all unused networks srm - to remove one or more networks Docker History This command is used to check the history of a docker image. The image name must be specified when using the command. This is how to use it -greatlearning@greatlearning:/home/greatlearning$ docker history httpdIMAGE CREATED CREATED BY SIZE COMMENTee39f68eb241 3 days ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0B3 days ago /bin/sh -c #(nop) EXPOSE 80 0B3 days ago /bin/sh -c #(nop) COPY file:c432ff61c4993ecd… 138B2 days ago /bin/sh -c set -eux? saveAptMark="$(apt-m… 49.1MB2 days ago /bin/sh -c #(nop) ENV HTTPD_PATCHES= 0B2 days ago /bin/sh -c #(nop) ENV HTTPD_SHA256= b4ca9d05… 0B2 days ago /bin/sh -c #(nop) ENV HTTPD_VERSION=2.4.39 0B2 days ago /bin/sh -c set -eux? apt-get update; apt-g... 35.4MB5 days ago /bin/sh -c #(nop) WORKDIR /usr/local/apache2 0B5 days ago /bin/sh -c mkdir -p "$HTTPD_PREFIX" && chow… 0B5 days ago /bin/sh -c #(nop) ENV PATH=/usr/local/apach… 0B5 days ago /bin/sh -c #(nop) ENV HTTPD_PREFIX=/usr/loc … 0B4 days ago /bin/sh -c #(nop) CMD ["bash"] 0B4 days ago /bin/sh -c #(nop) ADD file:71ac26257198ecf6a… 69.2 MB
- rmi docker
This command is used to free up disk space. The image id is used to remove the image when using this command.
docker rmi eb0e825dc3cf
- ps-a docker
This command is used to get the details of all running, stopped, or abandoned containers. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ docker ps -aCONTAINER ID AFBEELDING COMAND GEMAAKTE STATUS PORTNAMES09ca6feb6efc httpd "httpd-foreground" 51 seconds geleden Up 49 seconds 80/tcquf800/tcquf60 cker:2.7.0 "/etc/bootstrap . sh- d" 2 weeks ago Exited (137) 9 days ago better_naman9f397feb3a46 sequenceiq/hadoop-docker:2.7.0 "/etc/bootstrap.sh -…” 2 weeks ago Exited (255) 2 weeks ago 2122/ tcp, 80 -8033/ tcp, 8040/tcp, 8042/tcp, 8088/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50070/t07,tcp5005 6343d3b5a0 hello your world "/hello" 2 weeks ago Abandoned (0) 2 weeks ago mega_steven
- dockable copy
This command copies a docker file to the local system. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ sudo docker cp 09ca4feb7tfc:/usr/local/apache2/logs/httpd.pid /home/greatlearning/[sudo] greatlearning password: In the example above, we used the docker container with id 4feb79ft in the file 'http.pid.' To check if the file has been copied or not, run this command -greatlearning@greatlearning:/home/greatlearning$ lsDesktop Documents examples Examples.desktop httpd.pid nginx_new.yml nginx.yml
- docker records
This command is used to check the logs of all docker containers with the corresponding built-in id mentioned in the command. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ docker logs 09ca6feb6efcAH00558: httpd: Unable to reliably determine full server domain name with 172.17.0.2. Globally set the 'ServerName' directive to suppress this message AH00558: httpd: The fully qualified domain name of the server could not be reliably determined using 172.17.0.2. Set the "Servername" directive globally to suppress this message [Mon Jul 16 14:01:55.400472 2019] [MPM_EVENT: Notification] [PID 1: TID 140299791516800] AH00489: APACHE/2.4.39 (UNIX) Configured - [Mon. Jul 16 14:01:55.400615 2019] [kernel: notice] [pid 1: tid 140299791516800] AH00094: Command line: 'httpd -D FOREGROUND' [Mon. Jul vent: alert] [pid 1:tid 140299791516800] AH00491: SIGTERM caught, exitAH00558: httpd: could not reliably determine the fully qualified domain name of server with 172.17.0.2. Globally set the 'ServerName' directive to suppress this message AH00558: httpd: The fully qualified domain name of the server could not be reliably determined using 172.17.0.2. Configure the "Servername" directive globally to suppress this message [Mon Jul 15 14:08:38.259870 2019] [MPM_EVENT: Warning] [PID 1: TID 139974087980160] AH00489: [Mon Jul 15 14:08:38.260007 2019] [ kernel: warning] [pid 1: tid 139974087980160] AH00094: Command line: 'httpd -D FOREGROUND' [Mon. Jul 5_0901:15 Jul vent: warning] [pid 1:tid 139974087980160] AH00491: SIGTERM detected, exitAH00558: httpd: unable to reliably determine server FQDN with 172.17.0.2. Globally set the 'ServerName' directive to suppress this message AH00558: httpd: The fully qualified domain name of the server could not be reliably determined using 172.17.0.2. Set the 'Servername' directive globally to suppress this message [Mon Jul 16 14:10:43.782606 2019] [MPM_EVENT: Warning] [PID 1: TID 140281554879616] AH00489: APACHE/2.4.39 [Mon Jul 16 14:10 :43.782737 2019] [core: warning] [pid 1: tid 140281554879616] AH00094: command line: 'httpd -D FOREGROUND' AH005558 with fully qualified server name http1: unreliable. .0.2. Globally set the 'ServerName' directive to suppress this message AH00558: httpd: The fully qualified domain name of the server could not be reliably determined using 172.17.0.2. Set the "Servername" directive globally to suppress this message [Mon Jul 16 14:14:08.270906 2019] [MPM_EVENT: Warning] [PID 1: TID 140595254346880] AH00489: APACHE/2.4.39 [Mon Jul 16 14:14 :08.272628 2019] [core: warning] [pid 1: tid 140595254346880] AH00094: command line: 'httpd -D FOREGROUND'
- docker volume
This command creates a volume for the docker container that will be used to store data. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ docker volumen create7e7bc886f69bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0 Para verificar si este comando creó el siguiente comando volumen/greatlearning@greatlearning o no, $ docker volumen lsDRIVER VOLUME N AMElocal 7e7bc886 f69 bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0
- Log out of docker
This command disconnects you from the docker hub. Here's how to use it:
greatlearning@greatlearning:/home/greatlearning$ docker logout Eliminar credenciales para https://index.docker.io/v1/
conclusion
You can test the docker commands in your lab environment to practice them for source code development. We hope these 20 Docker Commands help you get started with Docker and learn how to perform basic operations without getting tired.Docker para Windowsand upgrade your docker skills.
FAQs
What are the important docker commands? ›
- Docker version.
- Docker search.
- Docker pull.
- Docker run.
- Docker ps.
- Docker stop.
- Docker restart.
- Docker kill.
Command | Usage |
---|---|
docker login | Log in to a Docker registry |
docker logout | Log out from a Docker registry |
docker logs | Fetch the logs of a container |
docker manifest | Manage Docker image manifests and manifest lists |
In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine.
What is the basic command for Docker run? ›The basic syntax for the command is: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] You can run containers from locally stored Docker images. If you use an image that is not on your system, the software pulls it from the online registry.
What are the two types of docker? ›There are three common Docker network types – bridge networks, used within a single host, overlay networks, for multi-host communication, and macvlan networks which are used to connect Docker containers directly to host network interfaces.
How many containers can docker handle? ›Runs Eight Containers per Host. The median company that adopts Docker runs eight containers simultaneously on each host, a figure that has climbed steadily over the years.
How to use docker step by step? ›- Step 1: Define the application dependencies. ...
- Step 2: Create a Dockerfile. ...
- Step 3: Define services in a Compose file. ...
- Step 4: Build and run your app with Compose. ...
- Step 5: Edit the Compose file to add a bind mount.
The easiest way to list Docker images is to use the “docker images” with no arguments. When using this command, you will be presented with the complete list of Docker images on your system. Alternatively, you can use the “docker image” command with the “ls” argument.
How to run an image in docker? ›- Step-1: Verify Docker version and also login to Docker Hub.
- Step-2: Pull Image from Docker Hub.
- Step-3: Run the downloaded Docker Image & Access the Application.
- Step-4: List Running Containers.
- Step-5: Connect to Container Terminal.
- Step-6: Container Stop, Start.
- AWS EKS - Elastic Kubernetes Service - Masterclass.
The Docker daemon ( dockerd ) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.
Where do I write docker commands? ›
By default, the Docker command line stores its configuration files in a directory called .docker within your $HOME directory.
How many CMD can a Dockerfile have? ›There can only be one CMD instruction in a Dockerfile . If you list more than one CMD then only the last CMD will take effect. The main purpose of a CMD is to provide defaults for an executing container.
What is CMD command in docker? ›The CMD command specifies the instruction that is to be executed when a Docker container starts.
What is the command to run a container? ›Running of containers is managed with the Docker run command. To run a container in an interactive mode, first launch the Docker container. Then hit Crtl+p and you will return to your OS shell. You will then be running in the instance of the CentOS system on the Ubuntu server.
What is run vs CMD command in docker? ›RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. CMD is the command the container executes by default when you launch the built image.
What are the 3 types of Docker volumes? ›Docker volumes are used to persist data from within a Docker container. There are a few different types of Docker volumes: host, anonymous, and, named.
What is Docker lifecycle? ›There are different stages when we create a Docker container which is known as Docker Container Lifecycle. Some of the states are: Created: A container that has been created but not started. Running: A container running with all its processes. Paused: A container whose processes have been paused.
How many layers are there in Docker? ›Docker stores all caches in /var/lib/docker/<driver> , where <driver> is the storage driver overlay2 again. Just as with layer directories, the directory name corresponds to the cache ID. The directory contains six layers in total as there is exactly one cache for each layer.
What are two ports in Docker? ›They need access to the network. You control network access to a Docker container via network ports. Docker has two tools for managing ports: Docker expose port and Docker port mapping.
How to run 2 commands in Docker? ›2. Using the docker run Command. To execute multiple commands in the docker run command, we can use the && operator to chain the commands together. The && operator executes the first command, and if it's successful, it executes the second command.
Can we have 2 Docker files? ›
Docker is a handy tool for containerization. It's so useful that sometimes, we want to have more than one Dockerfile in the project. Unfortunately, this goes against the straightforward convention of naming all Dockerfiles just “Dockerfile”.
What is the difference between a pod and a container? ›“A container runs logically in a pod (though it also uses a container runtime); A group of pods, related or unrelated, run on a cluster. A pod is a unit of replication on a cluster; A cluster can contain many pods, related or unrelated [and] grouped under the tight logical borders called namespaces.”
What is the daily limit of docker? ›For anonymous users, the rate limit is set to 100 pulls per 6 hours per IP address. For authenticated users, it's 200 pulls per 6 hour period. Users with a paid Docker subscription get up to 5000 pulls per day. If you require a higher number of pulls, you can also purchase an Enhanced Service Account add-on.
What is the maximum size of docker? ›Option | Description | Example value |
---|---|---|
max-size | The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure ( k , m , or g ). Defaults to 20m. | --log-opt max-size=10m |
The docker logs command has a flag, --follow or -f , that will display the logs and then continue watching and updating the display with changes to the log as they occur.
How to write a docker file? ›To create a Dockerfile, set up Docker and Docker Hub. Create the original Docker container and then create a file on it. Make changes to the container, and finally, create a new image.
How can I learn Docker fast? ›- Understand the difference between a container and a Virtual machine.
- Install docker on Linux.
- Create and run docker containers.
- Create persistent storage using docker volumes.
- Automate container creation process using Dockerfile.
- Learn essential docker commands.
- To verify if the container has stopped run docker ps -a command. The status of the stopped container would display as Exited . docker ps -a.
- Start a Docker container in a stopped state docker start <container_name/id> Connect:Direct service automatically starts inside the container.
To rebuild a Docker container, a new image must be created based on the changes made to the files within the container. This is accomplished by using the docker-compose up command with the --build flag, which instructs Docker to rebuild the container and create a new image based on the changes made to the files.
How to build a container in docker? ›- Set Up Docker on Your Computer. If you haven't already, create a DockerHub account and install Docker on your computer. ...
- Explore Docker Containers (optional) ...
- Create a Dockerfile. ...
- Build, Name, and Tag the Image. ...
- Test Locally. ...
- Push to DockerHub. ...
- Running Jobs.
What is the difference between docker image and container? ›
The key difference between a Docker image Vs a container is that a Docker image is a read-only immutable template that defines how a container will be realized. A Docker container is a runtime instance of a Docker image that gets created when the $ docker run command is implemented.
What is inside a docker image? ›A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run. When a user runs an image, it can become one or many instances of a container. Docker images have multiple layers, each one originates from the previous layer but is different from it.
What is rest API in Docker? ›The Docker Engine API is a RESTful API accessed by an HTTP client such as wget or curl , or the HTTP library which is part of most modern programming languages.
What port does Docker use? ›It is conventional to use port 2375 for un-encrypted, and port 2376 for encrypted communication with the daemon.
How many Docker components are there? ›There are three components in the Docker Engine: a) Server: It is the docker daemon called dockerd. It can create and manage docker images, i.e, Containers, networks. b) Rest API: It is used to instruct docker daemon what to do.
How to write CMD in Dockerfile? ›- Exec form: CMD [“executable”, “parameter1”, “parameter2”]
- Shell form: CMD command parameter1 parameter2.
Enter the docker stop command with the Container ID in the command line to stop the Container.
What is the difference between Dockerfile and docker image? ›A Dockerfile is the Docker image's source code. A Dockerfile is a text file containing various instructions and configurations. The FROM command in a Dockerfile identifies the base image from which you are constructing. When you run the Docker run command, Docker uses this file to build the image itself.
Can we create our own image in docker? ›- Write a Dockerfile for your application.
- Build the image with docker build command.
- Host your Docker image on a registry.
- Pull and run the image on the target machine.
The Docker Images and other objects are store inside the docker directory in the local machine. They are depending upon the default storage driver used by the machine. When we create Docker objects such as images, containers, volumes, etc. all these objects are store inside a directory in our local machine.
Can we override CMD in Dockerfile? ›
The docker run command has some options for setting or overriding the CMD and ENTRYPOINT instructions of the Dockerfile.
Can one Dockerfile create multiple images? ›A multistage build allows you to use multiple images to build a final product. In a multistage build, you have a single Dockerfile, but can define multiple images inside it to help build the final image.
What is the maximum length of docker CMD? ›@ZenithS You're right for Windows (8192 Characters), but Linux is not that easy.
What are the important features of docker? ›- Have multiple isolated environments on a single host. ...
- Preserves volume data when containers are created. ...
- Only recreate containers that have changed. ...
- Supports variables and moving a composition between environments. ...
- Development environments. ...
- Automated testing environments. ...
- Single host deployments.
Instruction | Description |
---|---|
RUN | Carry out the command in image in the course of build process |
CMD | Establish default arguments for container start |
ENTRYPOINT | Establish default command for container start |
EXPOSE | Determine port assignments for operating container |
The CMD command specifies the instruction that is to be executed when a Docker container starts.
How to use docker effectively? ›- Start with an appropriate base image. ...
- Use multistage builds. ...
- If you have multiple images with a lot in common, consider creating your own base image with the shared components, and basing your unique images on that.
Therefore, organizations can accelerate release cycles, scale operations on-demand and seamlessly make changes to code without application downtimes. Migrating from monolithic architecture to microservices is a popular Docker use case.
What are Docker tasks? ›A Docker Task is considered a Compute Resource; it adopts the permissions and environment variables required to perform actions using cloud resources within the stack. This occurs when a service discovery wire (dashed line) is connected from this resource to another cloud resource.
Where do I write Docker commands? ›By default, the Docker command line stores its configuration files in a directory called .docker within your $HOME directory.
What is Docker daemon? ›
The Docker daemon ( dockerd ) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.
What is the best system to run Docker? ›Any Linux OS can be used for docker but we prefer Boot2Docker or RancherOS. There are many reasons why you would want to choose one over the other. Boot2Docker is a better choice for Windows and Mac OS X users because it provides an easy way to get started with Docker.
How to build Docker image quickly? ›- Tip 1: Can you avoid building images? ...
- Tip 2: Structure your Dockerfile instructions like an inverted pyramid. ...
- Tip 3: Only copy files which are needed for the next step. ...
- Tip 4: Download less stuff. ...
- Tip 5: Use BuildKit with the new cache mount feature. ...
- In Conclusion.