{"id":9698,"date":"2021-07-19T08:42:15","date_gmt":"2021-07-19T05:42:15","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9698"},"modified":"2024-03-18T19:37:51","modified_gmt":"2024-03-18T16:37:51","slug":"install-docker-on-rocky-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-docker-on-rocky-linux\/","title":{"rendered":"Install Docker on Rocky Linux 8|9"},"content":{"rendered":"\n<p>Welcome to our guide on how to install docker on Rocky Linux 8\/Rocky Linux 9.&nbsp;<a href=\"https:\/\/docs.docker.com\/get-started\/\" target=\"_blank\" rel=\"noreferrer noopener\">Docker<\/a>&nbsp;is a platform that enables developers and system administrators to&nbsp;<strong>build, run, and share<\/strong>&nbsp;applications with containers.<\/p>\n\n\n\n<p>There exits two editions of docker available, <code>Docker CE<\/code>&nbsp;and&nbsp;<code>Docker EE<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker (Community Edition) is the open-source, community supported version of Docker and is available for free.<\/li>\n\n\n\n<li>Docker EE (Enterprise Edition) is a commercial\/premium version of docker and is supported by Docker Inc.<\/li>\n<\/ul>\n\n\n\n<p>We will be learning how to install and use Docker CE on Rocky Linux 8\/Rocky Linux 9.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-docker-on-rocky-linux-8-rocky-linux-9\">Installing Docker on Rocky Linux 8\/Rocky Linux 9<\/a><ul><li><a href=\"#install-docker-on-from-docker-repositories\">Install Docker on from Docker Repositories<\/a><ul><li><a href=\"#uninstall-old-docker-versions\">Uninstall old Docker Versions<\/a><\/li><li><a href=\"#install-docker-repository-on-rocky-linux-8-rocky-linux-9\">Install docker Repository on Rocky Linux 8\/Rocky Linux 9<\/a><\/li><li><a href=\"#install-docker-engine-docker-on-rocky-linux-8-rocky-linux-9\">Install Docker Engine (docker) on Rocky Linux 8\/Rocky Linux 9<\/a><\/li><\/ul><\/li><li><a href=\"#installing-docker-from-an-rpm-package\">Installing Docker from an RPM package<\/a><\/li><li><a href=\"#starting-docker-service\">Starting Docker Service<\/a><\/li><li><a href=\"#running-docker-as-a-non-root-user\">Running Docker as a non-root user<\/a><\/li><li><a href=\"#verifying-docker-installation\">Verifying docker installation<\/a><\/li><li><a href=\"#running-docker-images-on-rocky-linux-8-rocky-linux-9\">Running Docker Images on Rocky Linux 8\/Rocky Linux 9<\/a><\/li><li><a href=\"#using-docker-command\">Using\u00a0docker\u00a0command<\/a><\/li><li><a href=\"#running-docker-images-from-docker-hub\">Running Docker Images from Docker Hub<\/a><ul><li><a href=\"#searching-for-docker-images-on-docker-hub\">Searching for Docker Images on Docker Hub<\/a><\/li><li><a href=\"#pulling-docker-image-to-local-registry\">Pulling Docker Image to Local Registry<\/a><\/li><li><a href=\"#list-available-docker-images\">List Available Docker Images<\/a><\/li><li><a href=\"#running-a-docker-container-image\">Running a Docker Container Image<\/a><\/li><li><a href=\"#listing-docker-containers\">Listing Docker Containers<\/a><\/li><li><a href=\"#start-and-stop-docker-containers\">Start and Stop Docker Containers<\/a><\/li><li><a href=\"#removing-docker-containers\">Removing Docker Containers<\/a><\/li><li><a href=\"#removing-docker-images\">Removing Docker Images<\/a><\/li><\/ul><\/li><li><a href=\"#further-reading\">Further Reading<\/a><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-docker-on-rocky-linux-8-rocky-linux-9\">Installing Docker on Rocky Linux 8\/Rocky Linux 9<\/h2>\n\n\n\n<p>There are different methods in which you can install Docker;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installing docker from Docker Repositories<\/li>\n\n\n\n<li>Installing docker manually using the RPM binary package<\/li>\n\n\n\n<li>Installing docker using Docker Installation Script (<strong>Beyond the scope of this tutorial<\/strong>).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-docker-on-from-docker-repositories\">Install Docker on from Docker Repositories<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"uninstall-old-docker-versions\">Uninstall old Docker Versions<\/h4>\n\n\n\n<p>If any of the old docker versions are installed on your system, ensure that you remove them and their dependencies before you proceed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf remove docker*<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-docker-repository-on-rocky-linux-8-rocky-linux-9\">Install docker Repository on Rocky Linux 8\/Rocky Linux 9<\/h4>\n\n\n\n<p>To ensure seamless future upgrades of Docker packages, you can install it from their official repos. For this, you need to setup the Docker repositories on Rocky Linux 8\/Rocky Linux 9 by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf config-manager --add-repo https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo<\/pre>\n\n\n\n<p>The command above installs and enable docker repo on Rocky Linux 8\/Rocky Linux 9.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-docker-engine-docker-on-rocky-linux-8-rocky-linux-9\">Install Docker Engine (docker) on Rocky Linux 8\/Rocky Linux 9<\/h4>\n\n\n\n<p>Once the repos are in place, proceed to install <strong><code>docker-ce<\/code><\/strong> and other tools including&nbsp;<code><strong>containerd.io<\/strong><\/code>, an open and reliable container runtime on Rocky Linux 8\/Rocky Linux 9 and docker CLI utility, <strong><code>docker-ce-cli<\/code><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install docker-ce<\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Docker CE Stable - x86_64                                                                                                               138 kB\/s |  32 kB     00:00    \nDependencies resolved.\n========================================================================================================================================================================\n Package                                            Architecture                 Version                                   Repository                              Size\n========================================================================================================================================================================\nInstalling:\n docker-ce                                          x86_64                       3:24.0.7-1.el9                            docker-ce-stable                        24 M\nInstalling dependencies:\n checkpolicy                                        x86_64                       3.5-1.el9                                 appstream                              345 k\n container-selinux                                  noarch                       3:2.205.0-1.el9_2                         appstream                               50 k\n containerd.io                                      x86_64                       1.6.24-3.1.el9                            docker-ce-stable                        33 M\n docker-ce-cli                                      x86_64                       1:24.0.7-1.el9                            docker-ce-stable                       7.1 M\n fuse-common                                        x86_64                       3.10.2-5.el9.0.1                          baseos                                 8.1 k\n fuse-overlayfs                                     x86_64                       1.11-1.el9_2                              appstream                               71 k\n fuse3                                              x86_64                       3.10.2-5.el9.0.1                          appstream                               53 k\n fuse3-libs                                         x86_64                       3.10.2-5.el9.0.1                          appstream                               91 k\n libslirp                                           x86_64                       4.4.0-7.el9                               appstream                               68 k\n policycoreutils-python-utils                       noarch                       3.5-1.el9                                 appstream                               71 k\n python3-audit                                      x86_64                       3.0.7-103.el9                             appstream                               83 k\n python3-distro                                     noarch                       1.5.0-7.el9                               appstream                               36 k\n python3-libsemanage                                x86_64                       3.5-1.el9                                 appstream                               79 k\n python3-policycoreutils                            noarch                       3.5-1.el9                                 appstream                              2.0 M\n python3-setools                                    x86_64                       4.4.1-1.el9                               baseos                                 543 k\n python3-setuptools                                 noarch                       53.0.0-12.el9                             baseos                                 839 k\n slirp4netns                                        x86_64                       1.2.0-3.el9                               appstream                               45 k\n tar                                                x86_64                       2:1.34-6.el9_1                            baseos                                 876 k\nInstalling weak dependencies:\n docker-buildx-plugin                               x86_64                       0.11.2-1.el9                              docker-ce-stable                        13 M\n docker-ce-rootless-extras                          x86_64                       24.0.7-1.el9                              docker-ce-stable                       3.9 M\n docker-compose-plugin                              x86_64                       2.21.0-1.el9                              docker-ce-stable                        13 M\n\nTransaction Summary\n========================================================================================================================================================================\nInstall  22 Packages\n\nTotal download size: 98 M\nInstalled size: 385 M\nIs this ok [y\/N]: y\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-docker-from-an-rpm-package\">Installing Docker from an RPM package<\/h3>\n\n\n\n<p>You can as well install docker on using an RPM package.<\/p>\n\n\n\n<p>Download the latest versions of the individual packages installed above from&nbsp;<a href=\"https:\/\/download.docker.com\/linux\/centos\/\" target=\"_blank\" rel=\"noreferrer noopener\">Docker Packages page<\/a> for Rocky Linux. Choose your release number e.g 8 for Rocky 8 or 9 for Rocky 9. After that, navigate to <strong>\/x86_64\/stable\/Packages\/<\/strong> depending on your system arch.<\/p>\n\n\n\n<p><strong>Replace the version\/release numbers of the packages accordingly.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install https:\/\/download.docker.com\/linux\/centos\/9\/x86_64\/stable\/Packages\/docker-ce-24.0.7-1.el9.x86_64.rpm  -y<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install -y https:\/\/download.docker.com\/linux\/centos\/8\/x86_64\/stable\/Packages\/docker-ce-cli-24.0.7-1.el9.x86_64.rpm <\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install -y https:\/\/download.docker.com\/linux\/centos\/8\/x86_64\/stable\/Packages\/containerd.io-1.6.9-3.1.el9.x86_64.rpm <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"starting-docker-service\">Starting Docker Service<\/h3>\n\n\n\n<p>To start and enable Docker and Containerd service to run on system boot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl enable --now docker containerd<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-docker-as-a-non-root-user\">Running Docker as a non-root user<\/h3>\n\n\n\n<p>If you run Docker as standard user, you may get such an error;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[kifarunix@rocky9 ~]$ <strong>docker ps -a<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Got permission denied while trying to connect to the Docker daemon socket at unix:\/\/\/var\/run\/docker.sock: Get http:\/\/%2Fvar%2Frun%2Fdocker.sock\/v1.24\/containers\/json: dial unix \/var\/run\/docker.sock: connect: permission denied<\/code><\/pre>\n\n\n\n<p>Therefore, if you need to run docker as non-root user, simply add the user you want to run docker as to docker group or simply, grant the user sudo rights.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">usermod -aG docker USER<\/pre>\n\n\n\n<p>For example to add a user,&nbsp;kifarunix, to&nbsp;<code>docker<\/code>&nbsp;group;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">groups kifarunix<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">kifarunix : kifarunix <strong>docker<\/strong><\/pre>\n\n\n\n<p><strong>Next, log out and login again as the non root user that you added to the docker group so that your group membership can be re-evaluated<\/strong>.<\/p>\n\n\n\n<p>You can then run docker as a non root user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"verifying-docker-installation\">Verifying docker installation<\/h3>\n\n\n\n<p>Check the docker version;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker --version<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Docker version 24.0.7, build afdd53b<\/code><\/pre>\n\n\n\n<p>To verify that docker is running well, you can try running the&nbsp;<code>hello-world<\/code>&nbsp;container image.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[kifarunix@rocky8 ~]$ <strong>docker run hello-world<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>Unable to find image 'hello-world:latest' locally\nlatest: Pulling from library\/hello-world\nb8dfde127a29: Pull complete \nDigest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e\nStatus: Downloaded newer image for hello-world:latest\n\nHello from Docker!\nThis message shows that your installation appears to be working correctly.\n\nTo generate this message, Docker took the following steps:\n 1. The Docker client contacted the Docker daemon.\n 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n    (amd64)\n 3. The Docker daemon created a new container from that image which runs the\n    executable that produces the output you are currently reading.\n 4. The Docker daemon streamed that output to the Docker client, which sent it\n    to your terminal.\n\nTo try something more ambitious, you can run an Ubuntu container with:\n $ docker run -it ubuntu bash\n\nShare images, automate workflows, and more with a free Docker ID:\n https:\/\/hub.docker.com\/\n\nFor more examples and ideas, visit:\n https:\/\/docs.docker.com\/get-started\/\n\n<\/code><\/pre>\n\n\n\n<p>To list all running\/stopped containers;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[kifarunix@rocky8 ~]$ <strong>docker ps -a<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES\n4083300e3660        hello-world         \"\/hello\"            3 minutes ago       Exited (0) 5 minutes ago                       laughing_visvesvaraya\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-docker-images-on-rocky-linux-8-rocky-linux-9\">Running Docker Images on Rocky Linux 8\/Rocky Linux 9<\/h3>\n\n\n\n<p>While verifying docker installation above, we ran the hello-world docker container image. Building and running docker containerized applications is the next step after setting up your docker environment.<\/p>\n\n\n\n<p>So there are two things here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can either build and run your own docker container images or<\/li>\n\n\n\n<li>pull already created and shared images from&nbsp;<a href=\"https:\/\/hub.docker.com\/search?type=edition&amp;offering=community\" target=\"_blank\" rel=\"noreferrer noopener\">docker hub<\/a>, an image repository for Docker images.<\/li>\n<\/ul>\n\n\n\n<p>In this demo, we will learn how to use already created docker images from docker hub. With docker command, you can easily pull docker images from docker hub, as we did with the&nbsp;<strong>hello-world<\/strong>&nbsp;image above.<\/p>\n\n\n\n<p>If you want to build your own images and share on docker hub, then you need to sign up to create your own namespace for storing your images, which then can be publicly available.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-docker-command\">Using&nbsp;<code>docker<\/code>&nbsp;command<\/h3>\n\n\n\n<p><code>docker<\/code>&nbsp;command has quite a number of command line options for running various tasks.<\/p>\n\n\n\n<p>The command line syntax is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker [OPTIONS] COMMAND<\/pre>\n\n\n\n<p>You can view various command options and commands by executing;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker --help<\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>...\nOptions:\n      --config string      Location of client config files (default \"\/home\/kifarunix\/.docker\")\n  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with \"docker context use\")\n  -D, --debug              Enable debug mode\n...\nManagement Commands:\n  builder     Manage builds\n  config      Manage Docker configs\n  container   Manage containers\n...\nCommands:\n  attach      Attach local standard input, output, and error streams to a running container\n  build       Build an image from a Dockerfile\n  commit      Create a new image from a container's changes\n  cp          Copy files\/folders between a container and the local filesystem\n  create      Create a new container\n...\n<\/code><\/pre>\n\n\n\n<p>To view help for a specific docker command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker COMMAND --help<\/code><\/pre>\n\n\n\n<p>For example, to find the usage of docker&nbsp;<code>run<\/code>&nbsp;command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker run --help<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-docker-images-from-docker-hub\">Running Docker Images from Docker Hub<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"searching-for-docker-images-on-docker-hub\">Searching for Docker Images on Docker Hub<\/h4>\n\n\n\n<p>You can search for the specific publicly available Docker images on Docker Hub using&nbsp;<code><strong>docker search<\/strong><\/code>&nbsp;command. The docker search command syntax is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker search [OPTIONS] TERM<\/code><\/pre>\n\n\n\n<p>Use&nbsp;<strong><code>docker search --help<\/code><\/strong>&nbsp;to see more options.<\/p>\n\n\n\n<p>For example, to search all the images containing the term hello-world;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker search hello-world<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\nhello-world                                Hello World! (an example of minimal Dockeriz\u2026   1479      [OK]       \nkitematic\/hello-world-nginx                A light-weight nginx container that demonstr\u2026   150                  \ntutum\/hello-world                          Image to test docker deployments. Has Apache\u2026   83                   [OK]\ndockercloud\/hello-world                    Hello World!                                    19                   [OK]\ncrccheck\/hello-world                       Hello World web server in under 2.5 MB          15                   [OK]\nvad1mo\/hello-world-rest                    A simple REST Service that echoes back all t\u2026   5                    [OK]\narm32v7\/hello-world                        Hello World! (an example of minimal Dockeriz\u2026   3                    \nppc64le\/hello-world                        Hello World! (an example of minimal Dockeriz\u2026   2                    \ndatawire\/hello-world                       Hello World! Simple Hello World implementati\u2026   1                    [OK]\nmarkmnei\/hello-world-java-docker           Hello-World-Java-docker                         1                    [OK]\nthomaspoignant\/hello-world-rest-json       This project is a REST hello-world API to bu\u2026   1                    \nansibleplaybookbundle\/hello-world-db-apb   An APB which deploys a sample Hello World! a\u2026   1                    [OK]\nansibleplaybookbundle\/hello-world-apb      An APB which deploys a sample Hello World! a\u2026   1                    [OK]\n<\/code><\/pre>\n\n\n\n<p>Some column headings are self explanatory. Other columns include;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>STARS<\/strong>&nbsp;: Shows the number of likes the image has had.<\/li>\n\n\n\n<li><strong>OFFICIAL<\/strong>&nbsp;: Specifies whether the image is built from a trusted source.<\/li>\n\n\n\n<li><strong>AUTOMATED<\/strong>&nbsp;: Shows whether the image has been&nbsp;automatically build from source code in an external repository and automatically pushed to Docker repositories.<\/li>\n<\/ul>\n\n\n\n<p>Usually, an image with no prefix is considered official docker hub image, stable and being maintained. It also contains&nbsp;<strong>[OK]<\/strong>&nbsp;on the&nbsp;<strong>Official<\/strong>&nbsp;column.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pulling-docker-image-to-local-registry\">Pulling Docker Image to Local Registry<\/h4>\n\n\n\n<p>Once you have identified the image that you need to run, you can either pull it and store it on your local registry using the the&nbsp;<code><strong>docker pull<\/strong><\/code>&nbsp;command or simply run it using&nbsp;<code><strong>docker run<\/strong><\/code>&nbsp;command.<\/p>\n\n\n\n<p>For example, to search and pull an<a href=\"https:\/\/hub.docker.com\/_\/ubuntu\" target=\"_blank\" rel=\"noreferrer noopener\">&nbsp;Ubuntu system docker image<\/a>;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker search ubuntu<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>NAME                                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\nubuntu                                                    Ubuntu is a Debian-based Linux operating sys\u2026   12507     [OK]       \ndorowu\/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface \u2026   552                  [OK]\nwebsphere-liberty                                         WebSphere Liberty multi-architecture images \u2026   276       [OK]       \nrastasheep\/ubuntu-sshd                                    Dockerized SSH service, built on top of offi\u2026   254                  [OK]\nconsol\/ubuntu-xfce-vnc                                    Ubuntu container with \"headless\" VNC session\u2026   241                  [OK]\nubuntu-upstart                                            Upstart is an event-based replacement for th\u2026   111       [OK]       \nansible\/ubuntu14.04-ansible                               Ubuntu 14.04 LTS with ansible                   98                   [OK]\nneurodebian                                               NeuroDebian provides neuroscience research s\u2026   84        [OK]       \n1and1internet\/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                   [OK]\nopen-liberty                                              Open Liberty multi-architecture images based\u2026   47        [OK]       \nubuntu-debootstrap                                        debootstrap --variant=minbase --components=m\u2026   44        [OK]       \ni386\/ubuntu                                               Ubuntu is a Debian-based Linux operating sys\u2026   25                   \nsolita\/ubuntu-systemd                                     Ubuntu + systemd                                24                   [OK]\n...\n<\/code><\/pre>\n\n\n\n<p>Let us pull the official Ubuntu image.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker pull ubuntu<\/code><\/pre>\n\n\n\n<p>This will by default pull the most recent version of Ubuntu currently available, usually the latest LTS versions.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Using default tag: latest\nlatest: Pulling from library\/ubuntu\na31c7b29f4ad: Pull complete \nDigest: sha256:b3e2e47d016c08b3396b5ebe06ab0b711c34e7f37b98c9d37abe794b71cea0a2\nStatus: Downloaded newer image for ubuntu:latest\ndocker.io\/library\/ubuntu:latest\n<\/code><\/pre>\n\n\n\n<p>You can specify other tags for specific types of Ubuntu though;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker search ubuntu:20.04<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"list-available-docker-images\">List Available Docker Images<\/h4>\n\n\n\n<p>You can list locally available images using&nbsp;<code>docker images<\/code>&nbsp;command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker images<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>REPOSITORY    TAG       IMAGE ID       CREATED        SIZE\nubuntu        latest    c29284518f49   5 days ago     72.8MB\nhello-world   latest    d1165f221234   4 months ago   13.3kB<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"running-a-docker-container-image\">Running a Docker Container Image<\/h4>\n\n\n\n<p>Once you have pulled a container from Docker hub and is available locally, you can either run it with&nbsp;<code>docker run<\/code>&nbsp;or&nbsp;<code>docker create<\/code>&nbsp;command.<\/p>\n\n\n\n<p>With&nbsp;<code>docker run<\/code>, you can create a container, start it and access it using a shell to run any command inside it. The docker run command line syntax is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG\u2026]<\/code><\/pre>\n\n\n\n<p>For example, to run our Ubuntu image we pulled from Docker hub above in an interactive manner (<strong>option -i<\/strong>) drop to the shell (<strong>option -t<\/strong>, to allocate pseudo-TTY);<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker run -it ubuntu<\/code><\/pre>\n\n\n\n<p>This drops to the shell;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@9b93a21dac21:\/#<\/code><\/pre>\n\n\n\n<p>You are now inside an Ubuntu container, with a container ID,&nbsp;<strong><code>9b93a21dac21<\/code><\/strong>, as root user. Anything that you run or execute under this shell happens within the filesystem of the container itself.<\/p>\n\n\n\n<p>You can execute the commands directly without dropping to container shell;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker run ubuntu cat \/etc\/os-release<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>NAME=\"Ubuntu\"\nVERSION=\"20.04.2 LTS (Focal Fossa)\"\nID=ubuntu\nID_LIKE=debian\nPRETTY_NAME=\"Ubuntu 20.04.2 LTS\"\nVERSION_ID=\"20.04\"\nHOME_URL=\"https:\/\/www.ubuntu.com\/\"\nSUPPORT_URL=\"https:\/\/help.ubuntu.com\/\"\nBUG_REPORT_URL=\"https:\/\/bugs.launchpad.net\/ubuntu\/\"\nPRIVACY_POLICY_URL=\"https:\/\/www.ubuntu.com\/legal\/terms-and-policies\/privacy-policy\"\nVERSION_CODENAME=focal\nUBUNTU_CODENAME=focal\n<\/code><\/pre>\n\n\n\n<p>If you run the container interactively and started a shell, you can run your commands inside it.<\/p>\n\n\n\n<p>When you exit the shell, the shell attached to the container is detached and container stops. If you used the options, -i and -t when running docker container, you can exit the shell without stopping the container, use the keystrokes&nbsp;<code><strong>Ctrl + p<\/strong><\/code>&nbsp;then&nbsp;<code><strong>Ctrl + q<\/strong><\/code>.<\/p>\n\n\n\n<p>You can as well run container in background and print container ID<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker run -dit --name ubuntudemo ubuntu<\/code><\/pre>\n\n\n\n<p>To attach it to the console;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker attach ubuntudemo<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"listing-docker-containers\">Listing Docker Containers<\/h4>\n\n\n\n<p>You can list live (currently running) containers using&nbsp;<code><strong>docker ps<\/strong><\/code>&nbsp;command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker ps<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES\na1a815bb0de6   ubuntu    \"bash\"    5 seconds ago   Up 2 seconds             ubuntu-demo<\/code><\/pre>\n\n\n\n<p>To list all containers, those running and those exited;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker ps -a<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>CONTAINER ID   IMAGE         COMMAND                 CREATED              STATUS                          PORTS     NAMES\na1a815bb0de6   ubuntu        \"bash\"                  26 seconds ago       Up 22 seconds                             ubuntu-demo\n075d2a694b0c   ubuntu        \"bash\"                  About a minute ago   Exited (0) About a minute ago             ubuntudemo\nbe8a66af520a   ubuntu        \"cat \/etc\/os-release\"   2 minutes ago        Exited (0) 2 minutes ago                  eloquent_dirac\n9b93a21dac21   ubuntu        \"bash\"                  3 minutes ago        Exited (0) 2 minutes ago                  happy_elbakyan\n61407c90dae8   hello-world   \"\/hello\"                13 minutes ago       Exited (0) 13 minutes ago                 intelligent_gagarin\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"start-and-stop-docker-containers\">Start and Stop Docker Containers<\/h4>\n\n\n\n<p>You can start exited\/stopped containers using&nbsp;<code><strong>docker start<\/strong><\/code>&nbsp;command.<\/p>\n\n\n\n<p>For example, to start container named,&nbsp;<strong>happy_elbakyan<\/strong>, with an ID of&nbsp;<strong>9b93a21dac21<\/strong>, run the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker start happy_elbakyan<\/code><\/pre>\n\n\n\n<p>Or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker start <strong>9b93a21dac21<\/strong><\/code><\/pre>\n\n\n\n<p>Similarly, you can stop a running docker using its name or container ID with&nbsp;<code>docker stop<\/code>&nbsp;command.<\/p>\n\n\n\n<p>For example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker stop ubuntudemo<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"removing-docker-containers\">Removing Docker Containers<\/h4>\n\n\n\n<p>Once you are done with your containers, you can remove them using&nbsp;<code><strong>docker rm<\/strong><\/code>&nbsp;command.<\/p>\n\n\n\n<p>To remove a stopped container with an ID of&nbsp;<strong>9b7867c1daad<\/strong>, for example, in our&nbsp;<code>docker ps -a<\/code>&nbsp;output above;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker rm 9b7867c1daad<\/code><\/pre>\n\n\n\n<p>You cannot remove a running container unless you force the removal using using&nbsp;<code><strong>-f<\/strong><\/code>&nbsp;or&nbsp;<code><strong>--force<\/strong><\/code>&nbsp;option of docker rm command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker rm 1c280cf21322 -f<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"removing-docker-images\">Removing Docker Images<\/h4>\n\n\n\n<p>Docker images can as well be removed using&nbsp;<code>docker rmi<\/code>&nbsp;command. For example, you can list images and get the image ID of the specific image you want to remove;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker images -a<\/code><\/pre>\n\n\n\n<p>You can show numeric IDS using&nbsp;<code><strong>-q<\/strong><\/code>&nbsp;option.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker images -a -q<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>74435f89ab78\nbf756fb1ae65<\/code><\/pre>\n\n\n\n<p>Delete an image;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker rmi 74435f89ab78<\/code><\/pre>\n\n\n\n<p>Or use the name repo name;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker rmi ubuntu<\/code><\/pre>\n\n\n\n<p>Use option\u00a0<code><strong>-f<\/strong><\/code>\u00a0or\u00a0<strong><code>--force<\/code><\/strong>\u00a0to force the deletion.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"further-reading\">Further Reading<\/h3>\n\n\n\n<p><a href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/docker\/\" target=\"_blank\" rel=\"noreferrer noopener\">Docker Documentation<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-modsecurity-3-with-apache-in-a-docker-container\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install ModSecurity 3 with Apache in a Docker Container<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/deploy-a-single-node-elastic-stack-cluster-on-docker-containers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Deploy a Single Node Elastic Stack Cluster on Docker Containers<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-run-mariadb-as-a-docker-container\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Run MariaDB as a Docker Container<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our guide on how to install docker on Rocky Linux 8\/Rocky Linux 9.&nbsp;Docker&nbsp;is a platform that enables developers and system administrators to&nbsp;build, run,<\/p>\n","protected":false},"author":1,"featured_media":9718,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,1076,1077],"tags":[3860,1673,3859,3858,3587],"class_list":["post-9698","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-containers","category-docker","tag-containerd","tag-docker-containers","tag-docker-install-rocky-linux-8","tag-install-docker-on-rocky-linux-8","tag-rocky-linux-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9698"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=9698"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9698\/revisions"}],"predecessor-version":[{"id":21728,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9698\/revisions\/21728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9718"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}