{"id":114,"date":"2023-10-13T10:46:02","date_gmt":"2023-10-13T09:46:02","guid":{"rendered":"https:\/\/technology.corporatesstore.com\/?page_id=114"},"modified":"2023-11-03T07:34:31","modified_gmt":"2023-11-03T07:34:31","slug":"docker-overview","status":"publish","type":"page","link":"https:\/\/technology.corporatesstore.com\/index.php\/devops-culture\/docker-overview\/","title":{"rendered":"Docker Overview"},"content":{"rendered":"\n<p class=\"has-medium-font-size\"><strong>Docker vs Virtual Machines<\/strong><\/p>\n\n\n\n<p>While Docker and virtual machines serve a similar purpose, their performance, OS support, and portability differ significantly.<\/p>\n\n\n\n<p>The main difference is that Docker containers share the host\u2019s operating system, while virtual machines also have a guest operating system running on top of the host system. This method of operation affects the performance, hardware needs, and OS support. Check the table below for an in-depth comparison.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Criteria<\/th><th>Docker<\/th><th>Virtual Machine<\/th><\/tr><\/thead><tbody><tr><td>OS<\/td><td>Shared OS between containers.<\/td><td>New OS for each VM.<\/td><\/tr><tr><td>Security<\/td><td>Less secure because the operating system and kernel are shared.<\/td><td>More secure as VMs don\u2019t share the operating system.<\/td><\/tr><tr><td>Performance<\/td><td>Fast performance even with several containers.<\/td><td>More virtual machines equal less stable performance.<\/td><\/tr><tr><td>Boot-up time<\/td><td>Fast (seconds).<\/td><td>Slow (minutes).<\/td><\/tr><tr><td>Memory needs<\/td><td>Lightweight.<\/td><td>Require a lot of memory.<\/td><\/tr><tr><td>Storage needs<\/td><td>Usually megabytes.<\/td><td>Usually gigabytes.<\/td><\/tr><tr><td>Portability<\/td><td>Easy to deploy in different environments.<\/td><td>Hard to port a VM to another system.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Even though Docker\u2019s container technology comes on top in most aspects, virtual machines are more secure because the OS is kept independent from the hardware.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker vs Docker Engine<\/strong><\/p>\n\n\n\n<p>Docker is the name of the platform, while Docker Engine is an open-source container technology that consists of a Docker server (daemon), client, and APIs. People might also confuse the software with the Docker client because it\u2019s also called&nbsp;<strong>docker<\/strong>, only in lowercase letters.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Removing All Unused Docker Resources<\/strong><\/p>\n\n\n\n<p>Docker doesn\u2019t remove any unused data by itself, which can result in cluttering your disk space.<\/p>\n\n\n\n<p>If you\u2019d like to remove all images, containers, and networks that are not associated with a container,<\/p>\n\n\n\n<p><strong>docker system prune<\/strong><\/p>\n\n\n\n<p>This command will remove&nbsp;<strong>everything<\/strong>, including dangling images and stopped containers, as the following message will tell you:<\/p>\n\n\n\n<p>WARNING! This will remove:<\/p>\n\n\n\n<p>&#8211; all stopped containers <\/p>\n\n\n\n<p>&#8211; all networks not used by at least one container <\/p>\n\n\n\n<p>&#8211; all dangling images <\/p>\n\n\n\n<p>&#8211; all dangling build cache<\/p>\n\n\n\n<p>Are you sure you want to continue? [y\/N]<\/p>\n\n\n\n<p>In order to include all unused images, execute the following command:<\/p>\n\n\n\n<p><strong>docker system prune -a<\/strong><\/p>\n\n\n\n<p>Here\u2019s the warning message that you\u2019ll see before continuing:<\/p>\n\n\n\n<p>WARNING! This will remove:<\/p>\n\n\n\n<p>&#8211; all stopped containers<\/p>\n\n\n\n<p>&#8211; all networks not used by at least one container<\/p>\n\n\n\n<p>&#8211; all images without at least one container associated to them<\/p>\n\n\n\n<p>&#8211; all build cache<\/p>\n\n\n\n<p>Are you sure you want to continue? [y\/N]<\/p>\n\n\n\n<p>However, the previous two commands will not touch unused volumes \u2013 this is done deliberately for safety reasons.<\/p>\n\n\n\n<p>If you\u2019d like to remove that as well, use the following command:<\/p>\n\n\n\n<p><strong>docker system prune &#8211;volumes<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Objects<\/strong><\/p>\n\n\n\n<p>When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Container<\/strong><\/p>\n\n\n\n<p>Docker&nbsp;is among the most popular open-source container-based tools. It is used to run instances of Docker images since these create a new Docker container.<\/p>\n\n\n\n<p>In other words, images can be considered as a template that can be used to create containers. They contain information about what\u2019s required to develop and run a container. Another excellent image feature is that multiple images can be stored locally or remotely.<\/p>\n\n\n\n<p>A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.<\/p>\n\n\n\n<p>By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container&#8217;s network, storage, or other underlying subsystems are from other containers or from the host machine.<\/p>\n\n\n\n<p>A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that aren&#8217;t stored in persistent storage disappear.<a><\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create a Docker Container<\/strong><\/p>\n\n\n\n<p>In this section, we will use the&nbsp;<strong>Ubuntu 20.04<\/strong>&nbsp;virtual private server and assume you already have&nbsp;Docker installed. Therefore, start by accessing your VPS&nbsp;via SSH.<\/p>\n\n\n\n<p>To list all Dockers images on your system, you can use the following command:<\/p>\n\n\n\n<p><strong>sudo docker images<\/strong><\/p>\n\n\n\n<p>If you want to display additional information, enter the following command in the command line:<\/p>\n\n\n\n<p><strong>sudo docker images &#8211;help<\/strong><\/p>\n\n\n\n<p>Let&#8217;s say we don\u2019t have any Docker images on our system, so let\u2019s pull a new one first.<\/p>\n\n\n\n<p>To do that, first, go to the&nbsp;Docker Hub. Here you will find thousands of Docker base images.<\/p>\n\n\n\n<p>In this example, we will pull a MySQL image. Note that you can browse each image\u2019s page to see more details about the image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/The-view-of-Docker-hub.-Main-archive-where-users-can-find-Docker-containers.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>You can pull the new image to the current directory with the command:<\/p>\n\n\n\n<p><strong>docker pull &lt;image name or image id&gt;<\/strong><\/p>\n\n\n\n<p>Using the&nbsp;<strong>-q<\/strong>&nbsp;option will list only numeric IDs of images available on your system:<\/p>\n\n\n\n<p><strong>sudo docker images -q<\/strong><\/p>\n\n\n\n<p><strong>-f<\/strong>&nbsp;is the filter flag. If you want to list all images that are not dangling (tagged or referenced by a new container), use the following command in the command line:<\/p>\n\n\n\n<p><strong>sudo docker images -f &#8216;dangling=false&#8217;<\/strong><\/p>\n\n\n\n<p>Now that you know how to pull and locate an image to start a Docker container, it\u2019s time to run it. By running an image, you will create a container out of that image.<\/p>\n\n\n\n<p>To start a Docker container, use the&nbsp;<strong>docker run<\/strong>&nbsp;command:<\/p>\n\n\n\n<p><strong>docker run &lt;image_name&gt;<\/strong><\/p>\n\n\n\n<p>We will run the MySQL image. As such, the command will be:<\/p>\n\n\n\n<p><strong>docker run mysql<\/strong><\/p>\n\n\n\n<p>Our container is created but not started. To start it, use this command via the command prompt:<\/p>\n\n\n\n<p><strong>docker run &#8211;name MyContainer -it mysql bash<\/strong><\/p>\n\n\n\n<p>Here&nbsp;<strong>\u2013name MyContainer<\/strong>&nbsp;is how we wish to call the running process, while&nbsp;<strong>-it mysql bash<\/strong>&nbsp;names which container we are running.<\/p>\n\n\n\n<p>Now, open another terminal window. SSH into the server, and run the Docker&nbsp;<strong>ps<\/strong>&nbsp;command:<\/p>\n\n\n\n<p><strong>sudo docker ps -a<\/strong><\/p>\n\n\n\n<p>As you can see, the container named&nbsp;<strong>MyContainer<\/strong>&nbsp;is now running. To stop the container, issue the following command:<\/p>\n\n\n\n<p><strong>sudo docker stop MyContainer<\/strong><\/p>\n\n\n\n<p>If you wish to see the top process of a container, we can run this command:<\/p>\n\n\n\n<p><strong>docker top MyContainer<\/strong><\/p>\n\n\n\n<p><strong>MyContainer<\/strong>&nbsp;represents your container name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/The-terminal-window-shows-information-about-currently-running-container.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>To see additional stats, such as container ID, CPU utilization, or memory usage, use this command:<\/p>\n\n\n\n<p><strong>docker stats<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/The-terminal-window-is-displaying-docker-stats-command-output-1024x73.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>Lastly, if you need to terminate a Docker container, use the following:<\/p>\n\n\n\n<p><strong>sudo docker kill MyContainer<\/strong><\/p>\n\n\n\n<p>That\u2019s all there is to it \u2013 our Docker container is now ready to use.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Remove Docker Containers<\/strong><\/p>\n\n\n\n<p>In order to see the list of all Docker containers, you will need to run this command:<\/p>\n\n\n\n<p><strong>docker container ls -a<\/strong><\/p>\n\n\n\n<p>If you want to remove a specific container, enter the&nbsp;<strong>CONTAINER ID<\/strong>&nbsp;as shown in this example:<\/p>\n\n\n\n<p><strong>docker container rm CONTAINER_ID<\/strong><\/p>\n\n\n\n<p>To remove all the containers that&nbsp;<strong>stopped<\/strong>&nbsp;in the application, follow this command:<\/p>\n\n\n\n<p><strong>docker container prune<\/strong><\/p>\n\n\n\n<p>Take note that this will remove all stopped containers. In order to view the list of what containers will be deleted using the before mentioned command, use the&nbsp;<strong>\u2013filter&nbsp;<\/strong>flag:<\/p>\n\n\n\n<p><strong>docker container ls -a &#8211;filter status=created &#8211;filter status=exited<\/strong><\/p>\n\n\n\n<p>To limit the removal of containers that stopped, for example, according to the time frame, you can use the following command:<\/p>\n\n\n\n<p><strong>docker container prune &#8211;filter &#8220;until=24h&#8221;<\/strong><\/p>\n\n\n\n<p>If you want to remove a container once you\u2019re done working with it, you start one by adding a&nbsp;<strong>\u2013rm<\/strong>&nbsp;flag. Here\u2019s an example of how to remove such container:<\/p>\n\n\n\n<p><strong>docker run &#8211;rm CONTAINER_ID<\/strong><\/p>\n\n\n\n<p>When you\u2019re done, the container will be deleted automatically.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Hub<\/strong><\/p>\n\n\n\n<p>To make image sharing easier, Docker came up with a streamlined image-sharing platform \u2013 Docker Hub. Here users can easily share, upload and manage their images.<\/p>\n\n\n\n<p>No matter the operating system you use, whether it\u2019s&nbsp;<strong>Ubuntu<\/strong>&nbsp;on a&nbsp;<strong>virtual instance<\/strong>&nbsp;or&nbsp;<strong>Windows<\/strong>, users will still be able to find popular images like&nbsp;<strong>MySQL<\/strong>&nbsp;or&nbsp;<strong>WordPress<\/strong>&nbsp;on Docker Hub.<\/p>\n\n\n\n<p>Users can always pick the paid version of Docker Hub if the free version proves to be lacking. It offers more robust features, vulnerability scans, and concurrent builds.<\/p>\n\n\n\n<p>Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Hub Login<\/strong><\/p>\n\n\n\n<p>The official site for Docker hub is \u2212&nbsp;<a href=\"https:\/\/www.docker.com\/community-edition#\/add_ons\">https:\/\/www.docker.com\/community-edition#\/add_ons<\/a><\/p>\n\n\n\n<p>First you need to do a simple sign-up on Docker hub.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_hub_singup.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Once you have signed up, you will be logged into Docker Hub.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/technology.corporatesstore.com\/wp-content\/uploads\/2023\/10\/Docker-Login.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Browse Jenkins Image<\/strong><\/p>\n\n\n\n<p>Next, let\u2019s browse and find the Jenkins image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/technology.corporatesstore.com\/wp-content\/uploads\/2023\/10\/Jenkins-Image.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Run Jenkins<\/strong><\/p>\n\n\n\n<p>You can see the Docker&nbsp;<strong>pull<\/strong>&nbsp;command. This will be used to download the Jenkins image onto the local server.<\/p>\n\n\n\n<p>Now, go to the Ubuntu server and run the following command:<\/p>\n\n\n\n<p><strong>sudo docker pull jenkins\/jenkins<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/ubuntu_server.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>To run Jenkins, you need to run the following command:<\/p>\n\n\n\n<p><strong>sudo docker run -p 8080:8080 -p 50000:50000 jenkins<\/strong><\/p>\n\n\n\n<p>Note the following points about the above sudo command:<\/p>\n\n\n\n<ul>\n<li>We are using the sudo command to ensure it runs with root access.<\/li>\n\n\n\n<li>Here, jenkins is the name of the image we want to download from Docker hub and install on our Ubuntu machine.<\/li>\n\n\n\n<li>-p is used to map the port number of the internal Docker image to our main Ubuntu server so that we can access the container accordingly.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/sudo_command.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>You will then have Jenkins successfully running as a container on the Ubuntu machine.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Dockerfile<\/strong><\/p>\n\n\n\n<p>Docker images instruct the server on the exact requirements for creating a Docker container. On the other hand, a Docker file is an actual text file containing all the&nbsp;docker commands&nbsp;needed to assemble a container image. If a user wishes to create an image, they would need to create a Dockerfile with all the required commands for the server.<\/p>\n\n\n\n<p>If we use the Docker&nbsp;<strong>images<\/strong>&nbsp;command, we can see the existing images in our system. From the below screenshot, we can see that there are two images:&nbsp;<strong>centos<\/strong>&nbsp;and&nbsp;<strong>nsenter<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_file.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>But Docker also gives you the capability to create your own Docker images, and it can be done with the help of&nbsp;<strong>Docker Files<\/strong>. A Docker File is a simple text file with instructions on how to build your images.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create a Docker File<\/strong><\/p>\n\n\n\n<p>The following steps explain how you should go about creating a Docker File.<\/p>\n\n\n\n<p>Create a file called&nbsp;<strong>Docker File<\/strong>&nbsp;and edit it using&nbsp;<strong>vim<\/strong>. Please note that the name of the file has to be &#8220;Dockerfile&#8221; with &#8220;D&#8221; as capital.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/edit_vim.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Build your Docker File using the following instructions.<\/p>\n\n\n\n<p>#This is a sample Image<\/p>\n\n\n\n<p>FROM ubuntu<\/p>\n\n\n\n<p>MAINTAINER learn.technology@corporatesstore.com<\/p>\n\n\n\n<p>RUN apt-get update<\/p>\n\n\n\n<p>RUN apt-get install \u2013y nginx<\/p>\n\n\n\n<p>CMD [\u201cecho\u201d,\u201dImage created\u201d]<\/p>\n\n\n\n<p>The following points need to be noted about the above file:<\/p>\n\n\n\n<p>The first line &#8220;#This is a sample Image&#8221; is a comment. You can add comments to the Docker File with the help of the # command.<\/p>\n\n\n\n<p>The next line has to start with the FROM keyword. It tells docker, from which base image you want to base your image from. In our example, we are creating an image from the ubuntu image.<\/p>\n\n\n\n<p>The next command is the person who is going to maintain this image. Here you specify the MAINTAINER keyword and just mention the email ID.<\/p>\n\n\n\n<p>The RUN command is used to run instructions against the image. In our case, we first update our Ubuntu system and then install the nginx server on our ubuntu image.<\/p>\n\n\n\n<p>The last command is used to display a message to the user.<\/p>\n\n\n\n<p>Save the file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/build_the_image.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Images<\/strong><\/p>\n\n\n\n<p>An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the&nbsp;<strong>ubuntu<\/strong> image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.<\/p>\n\n\n\n<p>You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.<a><\/a><\/p>\n\n\n\n<p>In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let\u2019s take an example of the following command in Docker.<\/p>\n\n\n\n<p><strong>docker run hello-world<\/strong><\/p>\n\n\n\n<p>The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.<\/p>\n\n\n\n<p>The run command is used to mention that we want to create an instance of an image, which is then called a container.<\/p>\n\n\n\n<p>Finally, &#8220;hello-world&#8221; represents the image from which the container is made.<\/p>\n\n\n\n<p>Now let\u2019s look at how we can use the CentOS image available in Docker Hub to run CentOS on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine.<\/p>\n\n\n\n<p><strong>sudo docker run -it centos \/bin\/bash<\/strong><\/p>\n\n\n\n<p>Note the following points about the above sudo command:<\/p>\n\n\n\n<p>We are using the sudo command to ensure that it runs with root access.<\/p>\n\n\n\n<p>Here, centos is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.<\/p>\n\n\n\n<p>-it is used to mention that we want to run in interactive mode.<\/p>\n\n\n\n<p>\/bin\/bash is used to run the bash shell once CentOS is up and running.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Display Docker Images<\/strong><\/p>\n\n\n\n<p><strong>sudo docker images<\/strong><\/p>\n\n\n\n<p>When we run the above command, it will produce the following result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/displaying_docker_images.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>From the above output, you can see that the server has three images: centos, newcentos, and jenkins. Each image has the following attributes:<\/p>\n\n\n\n<p><strong>TAG <\/strong>\u2212 This is used to logically tag images.<\/p>\n\n\n\n<p><strong>Image ID<\/strong> \u2212 This is used to uniquely identify the image.<\/p>\n\n\n\n<p><strong>Created <\/strong>\u2212 The number of days since the image was created.<\/p>\n\n\n\n<p><strong>Virtual Size<\/strong> \u2212 The size of the image.<\/p>\n\n\n\n<p><strong>sudo docker images -q<\/strong><\/p>\n\n\n\n<p>When we run the above command, it will produce the following result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_images_q.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>This command is used to return only the Image ID\u2019s of the images.<\/p>\n\n\n\n<p><strong>sudo docker inspect jenkins<\/strong><\/p>\n\n\n\n<p>This command is used see the details of an image or container.<\/p>\n\n\n\n<p>When we run the above command, it will produce the following result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_inspect.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Download Docker Images<\/strong><\/p>\n\n\n\n<p>Images can be downloaded from Docker Hub using the Docker&nbsp;<strong>run<\/strong>&nbsp;command. Let\u2019s see in detail how we can do this.<\/p>\n\n\n\n<p><strong>sudo docker run centos<\/strong><\/p>\n\n\n\n<p>This command will download the&nbsp;<strong>centos<\/strong>&nbsp;image, if it is not already present, and run the OS as a container.<\/p>\n\n\n\n<p>When we run the above command, we will get the following result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/downloading_docker_images.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>You will now see the CentOS Docker image downloaded. Now, if we run the Docker&nbsp;<strong>images<\/strong>&nbsp;command to see the list of images on the system, we should be able to see the&nbsp;<strong>centos<\/strong>&nbsp;image as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/centos.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Remove Docker Images<\/strong><\/p>\n\n\n\n<p>In order to view all of your Docker images, you can use:<\/p>\n\n\n\n<p><strong>docker images -a<\/strong><\/p>\n\n\n\n<p>If you want to remove Docker image or a few, you can use this command and list the&nbsp;<strong>IMAGE ID<\/strong>&nbsp;as shown here:<\/p>\n\n\n\n<p><strong>docker image rm IMAGE_ID<\/strong><\/p>\n\n\n\n<p>The Docker images on the system can be removed via the&nbsp;<strong>docker rmi<\/strong>&nbsp;command. Let\u2019s look at this command in more detail.<\/p>\n\n\n\n<p><strong>sudo docker rmi 7a86f8ffcb25<\/strong><\/p>\n\n\n\n<p>Here,&nbsp;<strong>7a86f8ffcb25<\/strong>&nbsp;is the Image ID of the&nbsp;<strong>newcentos<\/strong>&nbsp;image.<\/p>\n\n\n\n<p>When we run the above command, it will produce the following result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/removing_docker_images.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>To remove dangling images that are most recent and untagged, we will use the&nbsp;<strong>&#8220;docker remove all images&#8221;<\/strong>&nbsp;command as shown here:<\/p>\n\n\n\n<p><strong>docker image prune<\/strong><\/p>\n\n\n\n<p>However, to remove Docker images that are present in existent containers that are also tagged, we can use this:<\/p>\n\n\n\n<p><strong>docker image prune \u2013a<\/strong><\/p>\n\n\n\n<p>If you wish to remove all images, for example, that may fall under a specific time frame, use the command:<\/p>\n\n\n\n<p><strong>docker image prune -a &#8211;filter &#8220;until=24h&#8221;<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Volumes<\/strong><\/p>\n\n\n\n<p>Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.<br>You can manage volumes using Docker CLI commands or the Docker API.<br>Volumes work on both Linux and Windows containers.<br>Volumes can be safely shared among multiple containers.<br>Volume drivers let you store volumes on remote hosts or cloud providers, encrypt the contents of volumes, or add other functionality.<br>New volumes can have their content pre-populated by a container.<br>In addition, volumes are often a better choice than persisting data in a container&#8217;s writable layer, because a volume doesn&#8217;t increase the size of the containers using it, and the volume&#8217;s contents exist outside the lifecycle of a given container.<\/p>\n\n\n\n<p>Volumes are used for multiple containers, and it is very likely there will be a number of either unused or stopped volume files.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Remove Docker Volumes<\/strong><\/p>\n\n\n\n<p>These files are not removed automatically, neither is there a setting in Docker to do so, as that can cause significant loss or damage to data.<\/p>\n\n\n\n<p>First, to get all Docker volume&nbsp;IDs, use the following command:<\/p>\n\n\n\n<p><strong>docker volume ls<\/strong><\/p>\n\n\n\n<p>If you want to remove a certain volume, use this command followed by the&nbsp;<strong>VOLUME NAME<\/strong>:<\/p>\n\n\n\n<p><strong>docker volume rm VOLUME_NAME<\/strong><\/p>\n\n\n\n<p>To remove all unused volumes using a single command, you can use the following:<\/p>\n\n\n\n<p><strong>docker volume prune<\/strong><\/p>\n\n\n\n<p>If Docker volumes have labels attached to them, you can also use this:<\/p>\n\n\n\n<p><strong>docker volume prune &#8211;filter &#8220;label!=keep&#8221;<\/strong><\/p>\n\n\n\n<p><strong>docker volume prune &#8211;filter &#8220;label!=keep&#8221;<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Networks<\/strong><\/p>\n\n\n\n<p>Docker Networking allows you to create a Network of Docker Containers managed by a master node called the manager.<br>The Docker network is a virtual network created by Docker to enable communication between Docker containers.<br>If two containers are running on the same host they can communicate with each other without the need for ports to be exposed to the host machine.<br>You may use Docker to manage your Docker hosts in any platform manner, regardless of whether they run Windows, Linux, or a combination of the two.<\/p>\n\n\n\n<p>Docker takes care of the networking aspects so that the containers can communicate with other containers and also with the Docker Host.<\/p>\n\n\n\n<p>If you do an&nbsp;<strong>ifconfig<\/strong>&nbsp;on the Docker Host, you will see the Docker Ethernet adapter. This adapter is created when Docker is installed on the Docker Host.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/ifconfig.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>This is a bridge between the Docker Host and the Linux Host.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>List Docker Networks<\/strong><\/p>\n\n\n\n<p><strong>sudo docker network ls<\/strong><\/p>\n\n\n\n<p>This command can be used to list all the networks associated with Docker on the host.<\/p>\n\n\n\n<p>The output of the above command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_networks.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Inspect a Docker Network<\/strong><\/p>\n\n\n\n<p><strong>sudo docker network inspect bridge<\/strong><\/p>\n\n\n\n<p>If you want to see more details on the network associated with Docker, you can use the Docker&nbsp;<strong>network inspect<\/strong>&nbsp;command.<\/p>\n\n\n\n<p>The output of the above command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/inspecting_docker_network.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now let\u2019s run a container and see what happens when we inspect the network again. Let\u2019s spin up an Ubuntu container with the following command:<\/p>\n\n\n\n<p><strong>sudo docker run -it ubuntu:latest \/bin\/bash<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/run_a_container_in_network.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now if we inspect our network name via the following command, you will now see that the container is attached to the bridge.<\/p>\n\n\n\n<p><strong>sudo docker network inspect bridge<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/container_attached_to_bridge.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create New Network<\/strong><\/p>\n\n\n\n<p>One can create a network in Docker before launching containers. This can be done with the following command:<\/p>\n\n\n\n<p><strong>sudo docker network create \u2013-driver bridge new_nw<\/strong><\/p>\n\n\n\n<p>The output of the above command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/long_id.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>You can now attach the new network when launching the container. So let\u2019s spin up an Ubuntu container with the following command:<\/p>\n\n\n\n<p><strong>sudo docker run \u2013it \u2013network=new_nw ubuntu:latest \/bin\/bash<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/new_network.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>And now when you inspect the network via the following command, you will see the container attached to the network.<\/p>\n\n\n\n<p><strong>sudo docker network inspect new_nw<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/new_nw.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Remove Docker Networks<\/strong><\/p>\n\n\n\n<p>Though Docker networks don\u2019t take much disk space, it can cause some problems if unnecessary files are not cleared from the disk.<\/p>\n\n\n\n<p>One problem is that it creates rules for&nbsp;iptables&nbsp;and bridge networks with routing table entries, which can cause some issues in the long run.<\/p>\n\n\n\n<p>For a full list of&nbsp;<strong>NETWORK IDs<\/strong>, use the following command:<\/p>\n\n\n\n<p><strong>docker network ls<\/strong><\/p>\n\n\n\n<p>In order to remove a specific network, you can use:<\/p>\n\n\n\n<p><strong>docker network rm NETWORK_ID<\/strong><\/p>\n\n\n\n<p>If you wish to remove all unused networks, use the following command:<\/p>\n\n\n\n<p><strong>docker network prune<\/strong><\/p>\n\n\n\n<p>For a filter based on the time frame, 24 hours in this example, you can simply enter instead:<\/p>\n\n\n\n<p><strong>docker network prune &#8211;filter &#8220;until=24h&#8221;<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Compose<\/strong><\/p>\n\n\n\n<p>Docker Compose is a utility that allows us to display images in Docker. It was created because many programs require other services to run.<\/p>\n\n\n\n<p>With Docker Composer we can define everything in a file, with all the images dependent on the main one and load them normally.<\/p>\n\n\n\n<p><strong>Docker Compose<\/strong>&nbsp;is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Compose Installation<\/strong><\/p>\n\n\n\n<p>The following steps need to be followed to get Docker Compose up and running.<\/p>\n\n\n\n<p>Download the necessary files from&nbsp;<strong>github<\/strong>&nbsp;using the following command:<\/p>\n\n\n\n<p><strong>curl -L &#8220;https:\/\/github.com\/docker\/compose\/releases\/download\/1.10.0-rc2\/dockercompose -$(uname -s) -$(uname -m)&#8221; -o \/home\/demo\/docker-compose<\/strong><\/p>\n\n\n\n<p>The above command will download the latest version of Docker Compose which at the time of writing this article is&nbsp;<strong>1.10.0-rc2<\/strong>. It will then store it in the directory&nbsp;<strong>\/home\/demo\/<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_compose.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Next, we need to provide&nbsp;<strong>execute privileges<\/strong>&nbsp;to the downloaded Docker Compose file, using the following command:<\/p>\n\n\n\n<p><strong>chmod +x \/home\/demo\/docker-compose<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/execute_privileges.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>We can then use the following command to see the&nbsp;<strong>compose<\/strong>&nbsp;version.<\/p>\n\n\n\n<p><strong>sudo .\/docker-compose -version<\/strong><\/p>\n\n\n\n<p>You will then get the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_compose_installation.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create Docker Compose File<\/strong><\/p>\n\n\n\n<p>Let\u2019s go ahead and create our first Docker Compose file. All Docker Compose files are YAML files. You can create one using the vim editor. So execute the following command to create the&nbsp;<strong>compose<\/strong>&nbsp;file:<\/p>\n\n\n\n<p><strong>sudo vim docker-compose.yml<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/compose_file.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let\u2019s take a close look at the various details of this file:<\/p>\n\n\n\n<ul>\n<li>The database and web keyword are used to define two separate services. One will be running our mysql database and the other will be our nginx web server.<\/li>\n\n\n\n<li>The image keyword is used to specify the image from dockerhub for our mysql and nginx containers<\/li>\n\n\n\n<li>For the database, we are using the ports keyword to mention the ports that need to be exposed for mysql.<\/li>\n\n\n\n<li>And then, we also specify the environment variables for mysql which are required to run mysql.<\/li>\n<\/ul>\n\n\n\n<p>Now let\u2019s run our Docker Compose file using the following command:<\/p>\n\n\n\n<p><strong>sudo .\/docker-compose up<\/strong><\/p>\n\n\n\n<p>This command will take the&nbsp;<strong>docker-compose.yml<\/strong>&nbsp;file in your local directory and start building the containers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_compose_yml.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Once executed, all the images will start downloading and the containers will start automatically.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/start_downloading.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>And when you do a&nbsp;<strong>docker ps<\/strong>, you can see that the containers are indeed up and running.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_compose_container.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Continuous Integration with Docker<\/strong><\/p>\n\n\n\n<p>Docker has integrations with many Continuous Integrations tools, which also includes the popular CI tool known as&nbsp;<strong>Jenkins<\/strong>. Within Jenkins, you have plugins available which can be used to work with containers. So let\u2019s quickly look at a Docker plugin available for the Jenkins tool.<\/p>\n\n\n\n<p>Let\u2019s go step by step and see what\u2019s available in Jenkins for Docker containers.<\/p>\n\n\n\n<p>Go to your Jenkins dashboard and click&nbsp;<strong>Manage Jenkins<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/manage_jenkins.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Go to&nbsp;<strong>Manage Plugins<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/manage_pluggins.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Search for Docker plugins. Choose the Docker plugin and click the&nbsp;<strong>Install<\/strong>&nbsp;<strong>without restart<\/strong>&nbsp;button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/install_without_restart.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Once the installation is completed, go to your job in the Jenkins dashboard. In our example, we have a job called&nbsp;<strong>Demo<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/demo.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>In the job, when you go to the Build step, you can now see the option to start and stop containers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/add_build_step.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>As a simple example, you can choose the further option to stop containers when the build is completed. Then, click the&nbsp;<strong>Save<\/strong>&nbsp;button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/stop_all_containers.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, just run your job in Jenkins. In the Console output, you will now be able to see that the command to Stop All containers has run.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/console_output.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Storage<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Storage Drivers<\/strong><\/p>\n\n\n\n<p>Docker has multiple storage drivers that allow one to work with the underlying storage devices. The following table shows the different storage drivers along with the technology used for the storage drivers.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Technology<\/th><th class=\"has-text-align-left\" data-align=\"left\">Storage Driver<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">OverlayFS<\/td><td class=\"has-text-align-left\" data-align=\"left\">overlay or overlay2<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">AUFS<\/td><td class=\"has-text-align-left\" data-align=\"left\">aufs<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Btrfs<\/td><td class=\"has-text-align-left\" data-align=\"left\">brtfs<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Device Manager<\/td><td class=\"has-text-align-left\" data-align=\"left\">devicemanager<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">VFS<\/td><td class=\"has-text-align-left\" data-align=\"left\">vfs<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">ZFS<\/td><td class=\"has-text-align-left\" data-align=\"left\">zfs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Let us now discuss some of the instances in which you would use the various storage drivers:<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>AUFS<\/strong><\/p>\n\n\n\n<ul>\n<li>This is a stable driver; can be used for production-ready applications.<\/li>\n\n\n\n<li>It has good memory usage and is good for ensuring a smooth Docker experience for containers.<\/li>\n\n\n\n<li>There is a high-write activity associated with this driver which should be considered.<\/li>\n\n\n\n<li>It\u2019s good for systems which are of Platform as a service type work.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Devicemapper<\/strong><\/p>\n\n\n\n<ul>\n<li>This is a stable driver; ensures a smooth Docker experience.<\/li>\n\n\n\n<li>This driver is good for testing applications in the lab.<\/li>\n\n\n\n<li>This driver is in line with the main Linux kernel functionality.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Btrfs<\/strong><\/p>\n\n\n\n<ul>\n<li>This driver is in line with the main Linux kernel functionality.<\/li>\n\n\n\n<li>There is a high-write activity associated with this driver which should be considered.<\/li>\n\n\n\n<li>This driver is good for instances where you maintain multiple build pools.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Ovelay<\/strong><\/p>\n\n\n\n<ul>\n<li>This is a stable driver and it is in line with the main Linux kernel functionality.<\/li>\n\n\n\n<li>It has a good memory usage.<\/li>\n\n\n\n<li>This driver is good for testing applications in the lab.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>ZFS<\/strong><\/p>\n\n\n\n<ul>\n<li>This is a stable driver and it is good for testing applications in the lab.<\/li>\n\n\n\n<li>It\u2019s good for systems which are of Platform-as-a-Service type work.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Storage Driver Info<\/strong><\/p>\n\n\n\n<p>To see the storage driver being used, issue the&nbsp;<strong>docker info<\/strong>&nbsp;command.<\/p>\n\n\n\n<p><strong>sudo docker info<\/strong><\/p>\n\n\n\n<p>The command will provide all relative information on the Docker component installed on the Docker Host.<\/p>\n\n\n\n<p>The following output shows that the main driver used is the&nbsp;<strong>aufs<\/strong>&nbsp;driver and that the root directory is stored in&nbsp;<strong>\/var\/lib\/docker\/aufs<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/aufs_driver.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Data Volumes<\/strong><\/p>\n\n\n\n<p>In Docker, you have a separate volume that can be shared across containers. These are known as data volumes. Some of the features of data volume are:<\/p>\n\n\n\n<ul>\n<li>They are initialized when the container is created.<\/li>\n\n\n\n<li>They can be shared and also reused amongst many containers.<\/li>\n\n\n\n<li>Any changes to the volume itself can be made directly.<\/li>\n\n\n\n<li>They exist even after the container is deleted.<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s look at our Jenkins container. Let\u2019s do a&nbsp;<strong>docker inspect<\/strong>&nbsp;to see the details of this image. We can issue the following command to write the output of the&nbsp;<strong>docker inspect<\/strong>&nbsp;command to a text file and then view the file accordingly.<\/p>\n\n\n\n<p><strong>sudo docker inspect Jenkins &gt; tmp.txt<\/strong><\/p>\n\n\n\n<p>When you view the text file using the&nbsp;<strong>more command<\/strong>, you will see an entry as&nbsp;<strong>JENKINS_HOME=\/var\/Jenkins_home<\/strong>.<\/p>\n\n\n\n<p>This is the mapping that is done within the container via the Jenkins image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/data_volumes.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now suppose you wanted to map the volume in the container to a local volume, then you need to specify the \u2013v option when launching the container. An example is shown below:<\/p>\n\n\n\n<p><strong>sudo docker run \u2013d \u2013v \/home\/demo:\/var\/jenkins_home \u2013p 8080:8080 \u2013p 50000:50000 jenkins<\/strong><\/p>\n\n\n\n<p>The \u2013v option is used to map the volume in the container which is&nbsp;<strong>\/var\/jenkins_home<\/strong>&nbsp;to a location on our Docker Host which is&nbsp;<strong>\/home\/demo<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/v_option.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now if you go to the&nbsp;<strong>\/home\/demo<\/strong>&nbsp;location on your Docker Host after launching your container, you will see all the container files present there.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/container_files.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Change Storage Driver<\/strong><\/p>\n\n\n\n<p>If you wanted to change to the storage driver used for a container, you can do so when launching the container. This can be done by using the&nbsp;<strong>\u2013volume-driver<\/strong>&nbsp;parameter when using the&nbsp;<strong>docker run<\/strong>&nbsp;command. An example is given below:<\/p>\n\n\n\n<p><strong>sudo docker run \u2013d &#8211;volume-driver=flocker \u2013v \/home\/demo:\/var\/jenkins_home \u2013p 8080:8080 \u2013p 50000:50000 jenkins<\/strong><\/p>\n\n\n\n<p>The&nbsp;<strong>\u2013volume-driver<\/strong>&nbsp;option is used to specify another storage driver for the container.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/volume_driver.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>To confirm that the driver has been changed, first let\u2019s use the&nbsp;<strong>docker ps<\/strong>&nbsp;command to see the running containers and get the container ID. So, issue the following command first:<\/p>\n\n\n\n<p><strong>sudo docker ps<\/strong><\/p>\n\n\n\n<p>Then issue a&nbsp;<strong>docker inspect<\/strong>&nbsp;against the container and put the output in a text file using the command.<\/p>\n\n\n\n<p><strong>sudo docker inspect 9bffb1bfebee &gt; temp.txt<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/docker_inspect_against_command.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>If you browse through the text file and go to the line which says&nbsp;<strong>VolumeDriver<\/strong>, you will see that the driver name has been changed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/driver_name_has_changed.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create a Volume<\/strong><\/p>\n\n\n\n<p>A volume can be created beforehand using the&nbsp;<strong>docker<\/strong>&nbsp;command. Let\u2019s learn more about this command.<\/p>\n\n\n\n<p><strong>sudo docker volume create \u2013-name = demo \u2013opt o = size = 100m<\/strong><\/p>\n\n\n\n<p>In the above command, we are creating a volume of size 100MB and with a name of demo.<\/p>\n\n\n\n<p>The output of the above command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/creating_a_volume.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>List all Volumes<\/strong><\/p>\n\n\n\n<p>You can also list all the&nbsp;<strong>docker volumes<\/strong>&nbsp;on a&nbsp;<strong>docker host<\/strong>. More details on this command is given below:<\/p>\n\n\n\n<p><strong>sudo docker volume ls<\/strong><\/p>\n\n\n\n<p>The output of the above command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.tutorialspoint.com\/docker\/images\/listing_all_volumes_output.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Docker Swarm<\/strong><\/p>\n\n\n\n<p>Docker offers its own orchestration system called Docker Swarm.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>UCP (Universal Control Plane)<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>DTR (Docker Trusted Registry)<\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker vs Virtual Machines While Docker and virtual machines serve a similar purpose, their performance, OS support, and portability differ significantly. The main difference is that Docker containers share the host\u2019s operating system, while virtual machines also have a guest operating system running on top of the host system. This method of operation affects the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":110,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/pages\/114"}],"collection":[{"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":22,"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/pages\/114\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/pages\/114\/revisions\/238"}],"up":[{"embeddable":true,"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/pages\/110"}],"wp:attachment":[{"href":"https:\/\/technology.corporatesstore.com\/index.php\/wp-json\/wp\/v2\/media?parent=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}