{"id":8015,"date":"2024-03-07T16:04:36","date_gmt":"2024-03-07T16:04:36","guid":{"rendered":"https:\/\/www.webhi.com\/how-to\/?p=8015"},"modified":"2024-03-07T16:07:44","modified_gmt":"2024-03-07T16:07:44","slug":"most-used-docker-commands-tutorial","status":"publish","type":"post","link":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/","title":{"rendered":"Essential Docker commands for beginners"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en.jpg\" alt=\"Docker commands beginners images containers networks volumes Compose\" class=\"wp-image-8033\" srcset=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en.jpg 1200w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en-300x169.jpg 300w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en-1024x576.jpg 1024w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en-768x432.jpg 768w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en-150x84.jpg 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p><strong>Docker<\/strong>&nbsp;has revolutionized the way developers build, ship, and run applications. It provides a consistent and isolated environment for applications to run, making it easier to develop, test, and deploy applications across different environments. However, for beginners, Docker can seem daunting with its own set of commands and terminology. In this comprehensive guide, we&#8217;ll take you through the essential Docker commands every beginner should know, with step-by-step instructions and examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction-to-docker\">Introduction to Docker<\/h2>\n\n\n\n<p>Before we dive into the commands, let&#8217;s briefly understand what Docker is and some key concepts.<\/p>\n\n\n\n<p>Docker is an open-source platform that enables developers to build, deploy, and run applications inside containers. Containers are lightweight, standalone, and executable packages that include everything needed to run an application, including code, runtime, system tools, libraries, and settings.<\/p>\n\n\n\n<p>Here are some key Docker concepts:<\/p>\n\n\n\n<ul>\n<li><strong>Docker Image<\/strong>: A read-only template that contains instructions for creating a Docker container. It&#8217;s like a blueprint for your application.<\/li>\n\n\n\n<li><strong>Docker Container<\/strong>: A runnable instance of a Docker image. It&#8217;s an isolated and secure environment where your application runs.<\/li>\n\n\n\n<li><strong>Docker Hub<\/strong>: A cloud-based registry service where you can find existing Docker images or push your own images.<\/li>\n\n\n\n<li><strong>Dockerfile<\/strong>: A text file that contains instructions for building a Docker image.<\/li>\n<\/ul>\n\n\n\n<p>Now, let&#8217;s dive into the essential Docker commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"docker-installation\">Docker Installation<\/h2>\n\n\n\n<p>Before you can start using Docker commands, you&#8217;ll need to install Docker on your machine. The installation process varies depending on your operating system. You can find the installation instructions for your specific OS on the official Docker website:&nbsp;<a href=\"https:\/\/docs.docker.com\/get-docker\/\">https:\/\/docs.docker.com\/get-docker\/<\/a><\/p>\n\n\n\n<p>Once you&#8217;ve installed Docker, you can verify the installation by running the following command in your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker --version<\/code><\/pre>\n\n\n\n<p>This command should display the version of Docker installed on your machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"essential-docker-commands\">Essential Docker Commands<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-docker-images\">1. Docker Images<\/h3>\n\n\n\n<p>Docker images are the building blocks of containers. Here are some essential commands for working with Docker images:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-docker-images\">List Docker Images<\/h4>\n\n\n\n<p>To list all the Docker images on your machine, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker images<\/code><\/pre>\n\n\n\n<p>This command will display a list of all the Docker images on your machine, along with their repository, tag, image ID, date created, and size.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pull-a-docker-image\">Pull a Docker Image<\/h4>\n\n\n\n<p>To download (pull) a Docker image from a registry (such as Docker Hub), run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker pull [image_name]:[tag]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[image_name]<\/code>&nbsp;with the name of the image you want to pull, and&nbsp;<code>[tag]<\/code>&nbsp;with the specific version or tag of the image (e.g.,&nbsp;<code>latest<\/code>,&nbsp;<code>16.04<\/code>, etc.). If you don&#8217;t specify a tag, Docker will automatically pull the&nbsp;<code>latest<\/code>&nbsp;tag.<\/p>\n\n\n\n<p>For example, to pull the latest version of the&nbsp;<code>nginx<\/code>&nbsp;image, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker pull nginx<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"remove-a-docker-image\">Remove a Docker Image<\/h4>\n\n\n\n<p>To remove a Docker image from your machine, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker rmi [image_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[image_id]<\/code>&nbsp;with the ID of the image you want to remove. You can find the image ID by running&nbsp;<code>docker images<\/code>.<\/p>\n\n\n\n<p>If the image has multiple tags, you&#8217;ll need to remove all associated tags before removing the image. You can do this by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker rmi [image_id] [image_id] ...<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[image_id]<\/code>&nbsp;with the IDs of all the tags you want to remove.<\/p>\n\n\n\n<p>Alternatively, you can use the&nbsp;<code>--force<\/code>&nbsp;flag to remove an image even if it&#8217;s being used by a running container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker rmi --force [image_id]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-docker-containers\">2. Docker Containers<\/h3>\n\n\n\n<p>Docker containers are running instances of Docker images. Here are some essential commands for working with Docker containers:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-docker-containers\">List Docker Containers<\/h4>\n\n\n\n<p>To list all running Docker containers on your machine, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker ps<\/code><\/pre>\n\n\n\n<p>If you want to list all containers (running and stopped), use the&nbsp;<code>-a<\/code>&nbsp;flag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker ps -a<\/code><\/pre>\n\n\n\n<p>This command will display various information about the containers, such as their IDs, names, images, creation times, and status.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"run-a-docker-container\">Run a Docker Container<\/h4>\n\n\n\n<p>To run a Docker container from an image, use the&nbsp;<code>run<\/code>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker run [options] [image_name]:[tag] [command]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[options]<\/code>&nbsp;with any additional options you want to pass to the container (e.g.,&nbsp;<code>-d<\/code>&nbsp;for running in detached mode,&nbsp;<code>-p<\/code>&nbsp;for port mapping,&nbsp;<code>-v<\/code>&nbsp;for mounting volumes, etc.),&nbsp;<code>[image_name]<\/code>&nbsp;with the name of the image you want to run,&nbsp;<code>[tag]<\/code>&nbsp;with the specific tag of the image (if desired), and&nbsp;<code>[command]<\/code>&nbsp;with the command you want to run inside the container (if needed).<\/p>\n\n\n\n<p>For example, to run the&nbsp;<code>nginx<\/code>&nbsp;image and map the container&#8217;s port&nbsp;<code>80<\/code>&nbsp;to your local port&nbsp;<code>8080<\/code>, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker run -d -p 8080:80 nginx<\/code><\/pre>\n\n\n\n<p>This command will run the&nbsp;<code>nginx<\/code>&nbsp;container in detached mode (<code>-d<\/code>) and map port&nbsp;<code>80<\/code>&nbsp;of the container to port&nbsp;<code>8080<\/code>&nbsp;on your local machine.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"startstop-a-docker-container\">Start\/Stop a Docker Container<\/h4>\n\n\n\n<p>To start a stopped Docker container, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker start [container_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the container you want to start.<\/p>\n\n\n\n<p>To stop a running Docker container, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker stop [container_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the container you want to stop.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"remove-a-docker-container\">Remove a Docker Container<\/h4>\n\n\n\n<p>To remove a stopped Docker container, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker rm [container_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the container you want to remove.<\/p>\n\n\n\n<p>If the container is running, you&#8217;ll need to stop it first before removing it. Alternatively, you can use the&nbsp;<code>--force<\/code>&nbsp;flag to remove a running container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker rm --force [container_id]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"execute-commands-in-a-running-container\">Execute Commands in a Running Container<\/h4>\n\n\n\n<p>To execute a command inside a running Docker container, use the&nbsp;<code>exec<\/code>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker exec [options] [container_id] [command]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[options]<\/code>&nbsp;with any additional options you want to pass (e.g.,&nbsp;<code>-it<\/code>&nbsp;for interactive mode),&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the running container, and&nbsp;<code>[command]<\/code>&nbsp;with the command you want to execute inside the container.<\/p>\n\n\n\n<p>For example, to open a bash shell inside a running container, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker exec -it [container_id] \/bin\/bash<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-docker-networks\">3. Docker Networks<\/h3>\n\n\n\n<p>Docker containers can communicate with each other and the host machine using Docker networks. Here are some essential commands for working with Docker networks:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-docker-networks\">List Docker Networks<\/h4>\n\n\n\n<p>To list all Docker networks on your machine, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker network ls<\/code><\/pre>\n\n\n\n<p>This command will display a list of all the Docker networks, along with their names, drivers, and scope.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-a-docker-network\">Create a Docker Network<\/h4>\n\n\n\n<p>To create a new Docker network, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker network create [options] [network_name]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[options]<\/code>&nbsp;with any additional options you want to pass (e.g.,&nbsp;<code>--driver<\/code>&nbsp;to specify the network driver), and&nbsp;<code>[network_name]<\/code>&nbsp;with the name you want to give to the new network.<\/p>\n\n\n\n<p>For example, to create a new bridge network named&nbsp;<code>my-network<\/code>, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker network create my-network<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"connect-a-container-to-a-network\">Connect a Container to a Network<\/h4>\n\n\n\n<p>To connect a running container to a Docker network, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker network connect [network_name] [container_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[network_name]<\/code>&nbsp;with the name of the network you want to connect the container to, and&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the running container.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"disconnect-a-container-from-a-network\">Disconnect a Container from a Network<\/h4>\n\n\n\n<p>To disconnect a container from a Docker network, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker network disconnect [network_name] [container_id]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[network_name]<\/code>&nbsp;with the name of the network you want to disconnect the container from, and&nbsp;<code>[container_id]<\/code>&nbsp;with the ID or name of the running container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-docker-volumes\">4. Docker Volumes<\/h3>\n\n\n\n<p>Docker volumes are used to persist data and share data between the host machine and containers, or between multiple containers. Here are some essential commands for working with Docker volumes:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-docker-volumes\">List Docker Volumes<\/h4>\n\n\n\n<p>To list all Docker volumes on your machine, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker volume ls<\/code><\/pre>\n\n\n\n<p>This command will display a list of all the Docker volumes, along with their names and drivers.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-a-docker-volume\">Create a Docker Volume<\/h4>\n\n\n\n<p>To create a new Docker volume, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker volume create [volume_name]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[volume_name]<\/code>&nbsp;with the name you want to give to the new volume.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"mount-a-volume-to-a-container\">Mount a Volume to a Container<\/h4>\n\n\n\n<p>To mount a volume to a Docker container, use the&nbsp;<code>-v<\/code>&nbsp;or&nbsp;<code>--volume<\/code>&nbsp;flag when running the container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker run -v [volume_name]:[container_path] [image_name]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[volume_name]<\/code>&nbsp;with the name or path of the volume you want to mount,&nbsp;<code>[container_path]<\/code>&nbsp;with the path inside the container where you want to mount the volume, and&nbsp;<code>[image_name]<\/code>&nbsp;with the name of the image you want to run.<\/p>\n\n\n\n<p>For example, to mount a volume named&nbsp;<code>app-data<\/code>&nbsp;to the&nbsp;<code>\/app\/data<\/code>&nbsp;directory inside a container running the&nbsp;<code>my-app<\/code>&nbsp;image, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker run -v app-data:\/app\/data my-app<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"remove-a-docker-volume\">Remove a Docker Volume<\/h4>\n\n\n\n<p>To remove a Docker volume, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker volume rm [volume_name]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[volume_name]<\/code>&nbsp;with the name of the volume you want to remove.<\/p>\n\n\n\n<p>If the volume is currently being used by a running container, you&#8217;ll need to stop and remove the container first before removing the volume.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-docker-compose\">5. Docker Compose<\/h3>\n\n\n\n<p>Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to define the services, networks, and volumes needed for your application. Here are some essential commands for working with Docker Compose:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"start-a-docker-compose-application\">Start a Docker Compose Application<\/h4>\n\n\n\n<p>To start a Docker Compose application, navigate to the directory containing the&nbsp;<code>docker-compose.yml<\/code>&nbsp;file and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker-compose up<\/code><\/pre>\n\n\n\n<p>This command will start all the services defined in the&nbsp;<code>docker-compose.yml<\/code>&nbsp;file. If you want to run the containers in the background, use the&nbsp;<code>-d<\/code>&nbsp;flag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker-compose up -d<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"stop-a-docker-compose-application\">Stop a Docker Compose Application<\/h4>\n\n\n\n<p>To stop a running Docker Compose application, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker-compose down<\/code><\/pre>\n\n\n\n<p>This command will stop and remove all the containers, networks, and volumes associated with the application.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-docker-compose-containers\">List Docker Compose Containers<\/h4>\n\n\n\n<p>To list all the containers associated with a Docker Compose application, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker-compose ps<\/code><\/pre>\n\n\n\n<p>This command will display a list of all the containers, along with their names, commands, and status.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"rebuild-docker-compose-containers\">Rebuild Docker Compose Containers<\/h4>\n\n\n\n<p>If you&#8217;ve made changes to your application code or configuration, you&#8217;ll need to rebuild the containers. To do this, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker-compose up --build<\/code><\/pre>\n\n\n\n<p>This command will rebuild the containers based on the updated Dockerfile and&nbsp;<code>docker-compose.yml<\/code>&nbsp;file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"6-docker-hub-and-private-registries\">6. Docker Hub and Private Registries<\/h3>\n\n\n\n<p>Docker Hub is a cloud-based registry service where you can find and share Docker images. You can also host your own private registry for storing and distributing your custom images. Here are some essential commands for working with Docker Hub and private registries:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"log-in-to-docker-hub\">Log in to Docker Hub<\/h4>\n\n\n\n<p>To log in to your Docker Hub account, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker login<\/code><\/pre>\n\n\n\n<p>This command will prompt you to enter your Docker Hub username and password.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"push-an-image-to-docker-hub\">Push an Image to Docker Hub<\/h4>\n\n\n\n<p>To push a Docker image to your Docker Hub repository, first, you&#8217;ll need to tag the image with your Docker Hub username:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker tag [image_id] [username]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[image_id]<\/code>&nbsp;with the ID of the image you want to push,&nbsp;<code>[username]<\/code>&nbsp;with your Docker Hub username,&nbsp;<code>[image_name]<\/code>&nbsp;with the name you want to give to the image, and&nbsp;<code>[tag]<\/code>&nbsp;with the desired tag (e.g.,&nbsp;<code>latest<\/code>,&nbsp;<code>v1.0<\/code>, etc.).<\/p>\n\n\n\n<p>Once the image is tagged, you can push it to Docker Hub:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker push [username]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pull-an-image-from-docker-hub\">Pull an Image from Docker Hub<\/h4>\n\n\n\n<p>To pull an image from Docker Hub, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker pull [username]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[username]<\/code>&nbsp;with the Docker Hub username of the image owner,&nbsp;<code>[image_name]<\/code>&nbsp;with the name of the image, and&nbsp;<code>[tag]<\/code>&nbsp;with the desired tag.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"log-in-to-a-private-registry\">Log in to a Private Registry<\/h4>\n\n\n\n<p>To log in to a private Docker registry, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker login [registry_url]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[registry_url]<\/code>&nbsp;with the URL of your private registry. This command will prompt you to enter your registry credentials (username and password).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"push-an-image-to-a-private-registry\">Push an Image to a Private Registry<\/h4>\n\n\n\n<p>To push a Docker image to a private registry, first, you&#8217;ll need to tag the image with the registry URL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker tag [image_id] [registry_url]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[image_id]<\/code>&nbsp;with the ID of the image you want to push,&nbsp;<code>[registry_url]<\/code>&nbsp;with the URL of your private registry,&nbsp;<code>[image_name]<\/code>&nbsp;with the name you want to give to the image, and&nbsp;<code>[tag]<\/code>&nbsp;with the desired tag.<\/p>\n\n\n\n<p>Once the image is tagged, you can push it to the private registry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker push [registry_url]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pull-an-image-from-a-private-registry\">Pull an Image from a Private Registry<\/h4>\n\n\n\n<p>To pull an image from a private registry, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker pull [registry_url]\/[image_name]:[tag]<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>[registry_url]<\/code>&nbsp;with the URL of your private registry,&nbsp;<code>[image_name]<\/code>&nbsp;with the name of the image, and&nbsp;<code>[tag]<\/code>&nbsp;with the desired tag.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>In this comprehensive guide, we&#8217;ve covered the essential Docker commands every beginner should know. From working with Docker images and containers to managing networks, volumes, and registries, you now have the foundational knowledge to start using Docker effectively.<\/p>\n\n\n\n<p>Remember, Docker is a powerful tool, and there are many more advanced commands and features to explore as you gain more experience. Practice, experiment, and don&#8217;t hesitate to refer back to this guide whenever you need a refresher.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker&nbsp;has revolutionized the way developers build, ship, and run applications. It provides a consistent and isolated environment for applications to run, making it easier to develop, test, and deploy applications across different environments. However, for beginners, Docker can seem daunting with its own set of commands and terminology. In this comprehensive guide, we&#8217;ll take you ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[188,182],"tags":[],"yoast_head":"\n<title>Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations<\/title>\n<meta name=\"description\" content=\"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"og:description\" content=\"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webhi.technology\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-07T16:04:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-07T16:07:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en.jpg\" \/>\n<meta name=\"author\" content=\"webhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:site\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\"},\"author\":{\"name\":\"webhi\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\"},\"headline\":\"Essential Docker commands for beginners\",\"datePublished\":\"2024-03-07T16:04:36+00:00\",\"dateModified\":\"2024-03-07T16:07:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\"},\"wordCount\":1954,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"articleSection\":[\"CMS &amp; Web development\",\"Virtualization &amp; Cloud computing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\",\"name\":\"Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\"},\"datePublished\":\"2024-03-07T16:04:36+00:00\",\"dateModified\":\"2024-03-07T16:07:44+00:00\",\"description\":\"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webhi.com\/how-to\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Essential Docker commands for beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"name\":\"WebHi Tutorials &amp; Documentations\",\"description\":\"System administration and knowledge base\",\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\",\"name\":\"WebHi Technology\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"width\":288,\"height\":95,\"caption\":\"WebHi Technology\"},\"image\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webhi.technology\",\"https:\/\/twitter.com\/WebHiTechnology\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\",\"name\":\"webhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435\",\"caption\":\"webhi\"},\"sameAs\":[\"https:\/\/www.webhi.com\/how-to\"],\"url\":\"https:\/\/www.webhi.com\/how-to\/author\/webhi\/\"}]}<\/script>\n","yoast_head_json":{"title":"Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations","description":"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations","og_description":"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.","og_url":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/","og_site_name":"WebHi Tutorials &amp; Documentations","article_publisher":"https:\/\/www.facebook.com\/webhi.technology","article_published_time":"2024-03-07T16:04:36+00:00","article_modified_time":"2024-03-07T16:07:44+00:00","og_image":[{"url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/03\/docker_guide_en.jpg"}],"author":"webhi","twitter_card":"summary_large_image","twitter_creator":"@WebHiTechnology","twitter_site":"@WebHiTechnology","twitter_misc":{"Written by":"webhi","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/"},"author":{"name":"webhi","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54"},"headline":"Essential Docker commands for beginners","datePublished":"2024-03-07T16:04:36+00:00","dateModified":"2024-03-07T16:07:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/"},"wordCount":1954,"commentCount":0,"publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"articleSection":["CMS &amp; Web development","Virtualization &amp; Cloud computing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/","url":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/","name":"Essential Docker commands for beginners - WebHi Tutorials &amp; Documentations","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/#website"},"datePublished":"2024-03-07T16:04:36+00:00","dateModified":"2024-03-07T16:07:44+00:00","description":"Discover the essential Docker commands every beginner should know. This comprehensive guide covers Docker images, containers, networks, volumes, Docker Compose, and private registries with step-by-step instructions and examples.","breadcrumb":{"@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhi.com\/how-to\/most-used-docker-commands-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhi.com\/how-to\/"},{"@type":"ListItem","position":2,"name":"Essential Docker commands for beginners"}]},{"@type":"WebSite","@id":"https:\/\/www.webhi.com\/how-to\/#website","url":"https:\/\/www.webhi.com\/how-to\/","name":"WebHi Tutorials &amp; Documentations","description":"System administration and knowledge base","publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webhi.com\/how-to\/#organization","name":"WebHi Technology","url":"https:\/\/www.webhi.com\/how-to\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/","url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","contentUrl":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","width":288,"height":95,"caption":"WebHi Technology"},"image":{"@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webhi.technology","https:\/\/twitter.com\/WebHiTechnology"]},{"@type":"Person","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54","name":"webhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/","url":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435","contentUrl":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435","caption":"webhi"},"sameAs":["https:\/\/www.webhi.com\/how-to"],"url":"https:\/\/www.webhi.com\/how-to\/author\/webhi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8015"}],"collection":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/comments?post=8015"}],"version-history":[{"count":7,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8015\/revisions"}],"predecessor-version":[{"id":8038,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8015\/revisions\/8038"}],"wp:attachment":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/media?parent=8015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/categories?post=8015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/tags?post=8015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}