{"id":6252,"date":"2020-06-28T10:19:52","date_gmt":"2020-06-28T07:19:52","guid":{"rendered":"https:\/\/kifarunix.com\/?p=6252"},"modified":"2024-03-14T21:11:42","modified_gmt":"2024-03-14T18:11:42","slug":"install-and-use-docker-ce-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-use-docker-ce-on-centos-8\/","title":{"rendered":"Install and Use Docker CE on CentOS 8"},"content":{"rendered":"\n
Welcome to our guide on how to install and use docker ce on CentOS 8. Docker<\/a> is a platform that enables developers and system administrators to build, run, and share<\/strong> applications with containers.<\/p>\n\n\n\n The exits two editions of docker available. There are different methods in which you can install Docker CE on CentOS 8;<\/p>\n\n\n\n Ensure that your system package cache is up-to-date.<\/p>\n\n\n\n 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 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 CentOS 8 by executing the command below;<\/p>\n\n\n\n The command above installs and enable Docker CE repo on CentOS 8.<\/p>\n\n\n\n Once the repos are in place, proceed to install docker-ce and other tools including Next, install Docker CE and Docker CE CLI utility.<\/p>\n\n\n\n You can as well install Docker ce on CentOS 8 using an RPM package.<\/p>\n\n\n\n Download the latest versions of the individual packages installed above from Docker Packages page<\/a>.<\/p>\n\n\n\n Replace the version\/release numbers of the packages accordingly.<\/p>\n\n\n\n To start and enable Docker and Containerd service to run on system boot;<\/p>\n\n\n\n If you run Docker as standard user, you may get such an error;<\/p>\n\n\n\n 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. For example to add a user, 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 You can then run docker as a non root user.<\/p>\n\n\n\n Check the docker version;<\/p>\n\n\n\n To verify that Docker CE is running well, you can try running the To list running containers;<\/p>\n\n\n\n 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 So there are two things here: You can either build and run your own docker container images or pull already created and shared images from docker hub<\/a>, an image repository for Docker images.<\/p>\n\n\n\n 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 hello-world<\/strong> image above.<\/p>\n\n\n\n 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 The command line syntax is;<\/p>\n\n\n\n You can view various command options and commands by executing;<\/p>\n\n\n\n To view help for a specific docker command;<\/p>\n\n\n\n For example, to find the usage of docker You can search for the specific publicly available Docker images on Docker Hub using Use For example, to search all the images containing the term hello-world;<\/p>\n\n\n\n Some column headings are self explanatory. Other columns include;<\/p>\n\n\n\n Usually, an image with no prefix is considered official docker hub image, stable and being maintained. It also contains [OK]<\/strong> on the Official<\/strong> column.<\/p>\n\n\n\n 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 For example, to search and pull an Ubuntu system docker image<\/a>;<\/p>\n\n\n\n Let us pull the official Ubuntu image.<\/p>\n\n\n\n This will by default pull the most recent version of Ubuntu currently available, usually the latest LTS versions.<\/p>\n\n\n\n You can specify other tags for specific types of Ubuntu though;<\/p>\n\n\n\n You can list locally available images using Once you have pulled a container from Docker hub and is available locally, you can either run it with With For example, to run our Ubuntu image we pulled from Docker hub above in an interactive manner (option -i<\/strong>) drop to the shell (option -t<\/strong>, to allocate pseudo-TTY);<\/p>\n\n\n\n This drops to the shell;<\/p>\n\n\n\n You are now inside an Ubuntu container, with a container ID, 43ff7a031a0b<\/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 You can execute the commands directly without dropping to container shell;<\/p>\n\n\n\n If you run the container interactively and started a shell, you can run your commands inside it.<\/p>\n\n\n\n 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 You can as well run container in background and print container ID<\/p>\n\n\n\n To attach it to the console;<\/p>\n\n\n\n You can list live (currently running) containers using To list all containers, those running and those exited;<\/p>\n\n\n\n You can start exited\/stopped containers using Or<\/p>\n\n\n\n Similarly, you can stop a running docker using its name or container ID with Once you are done with your containers, you can remove them using To remove a stopped container with an ID of 9b7867c1daad<\/strong>, for example, in our You cannot remove a running container unless you force the removal using using Docker images can as well be removed using You can show numeric IDS using Delete an image;<\/p>\n\n\n\n Or use the name repo name;<\/p>\n\n\n\n Use option Docker Documentation<\/a><\/p>\n\n\n\n Install Docker CE on Ubuntu 20.04<\/a><\/p>\n\n\n\n Install and Use Docker on Debian 10 Buster<\/a><\/p>\n\n\n\nDocker CE<\/code> and
Docker EE<\/code><\/p>\n\n\n\n
\n
Installing Docker CE on CentOS 8<\/a><\/h2>\n\n\n\n
\n
Installing Docker CE from Docker Repositories<\/h3>\n\n\n\n
Run System Update<\/h4>\n\n\n\n
dnf update<\/code><\/pre>\n\n\n\n
Uninstall Docker Versions<\/h4>\n\n\n\n
dnf remove docker*<\/code><\/pre>\n\n\n\n
Install Docker CE Repository on CentOS 8<\/h4>\n\n\n\n
dnf config-manager --add-repo https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo<\/code><\/pre>\n\n\n\n
Install Docker Engine (Docker CE) on CentOS 8<\/h4>\n\n\n\n
containerd.io<\/code>, an open and reliable container runtime on CentOS 8.<\/p>\n\n\n\n
dnf install docker-ce docker-ce-cli containerd.io<\/code><\/pre>\n\n\n\n
Installing Docker CE from an RPM package<\/h3>\n\n\n\n
for i in containerd.io-1.4.6-3.1.el8.x86_64.rpm docker-ce-20.10.7-3.el8.x86_64.rpm docker-ce-cli-20.10.7-3.el8.x86_64.rpm; do dnf install -y https:\/\/download.docker.com\/linux\/centos\/8\/x86_64\/stable\/Packages\/<\/a>$i; done<\/code><\/pre>\n\n\n\n
Starting Docker Service<\/h3>\n\n\n\n
systemctl enable --now docker containerd<\/code><\/pre>\n\n\n\n
Running Docker as a non-root user<\/a><\/h3>\n\n\n\n
[koromicha@centos8 ~]$ docker ps -a<\/code><\/pre>\n\n\n\n
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:\/\/\/var\/run\/docker.sock: ...<\/strong>\n\/var\/run\/docker.sock: connect: permission denied.\nSee 'docker run --help'.<\/code><\/pre>\n\n\n\n
koromicha<\/code>, to
docker<\/code> group;<\/p>\n\n\n\n
usermod -aG docker koromicha<\/code><\/pre>\n\n\n\n
groups koromicha<\/code><\/pre>\n\n\n\n
koromicha : koromicha docker<\/strong><\/code><\/pre>\n\n\n\n
Verifying Docker CE installation<\/h3>\n\n\n\n
docker --version<\/code><\/pre>\n\n\n\n
Docker version 19.03.12, build 48a66213fe<\/code><\/pre>\n\n\n\n
hello-world<\/code> container image.<\/p>\n\n\n\n
[koromicha@centos8 ~]$ docker run hello-world<\/strong><\/code><\/pre>\n\n\n\n
Unable to find image 'hello-world:latest' locally\nlatest: Pulling from library\/hello-world\n0e03bdcc26d7: Pull complete \nDigest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76\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<\/code><\/pre>\n\n\n\n
[koromicha@centos8 ~]$ docker ps -a<\/strong><\/code><\/pre>\n\n\n\n
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n4083300e3660 hello-world \"\/hello\" 3 minutes ago Exited (0) 5 minutes ago laughing_visvesvaraya<\/code><\/pre>\n\n\n\n
Running Docker Images on CentOS 8<\/a><\/h2>\n\n\n\n
Using
docker<\/code> command<\/a><\/h3>\n\n\n\n
docker<\/code> command has quite a number of command line options for running various tasks.<\/p>\n\n\n\n
docker [OPTIONS] COMMAND<\/code><\/pre>\n\n\n\n
docker --help<\/code><\/pre>\n\n\n\n
...\nOptions:\n --config string Location of client config files (default \"\/home\/koromicha\/.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
docker COMMAND --help<\/code><\/pre>\n\n\n\n
run<\/code> command;<\/p>\n\n\n\n
docker run --help<\/code><\/pre>\n\n\n\n
Running Docker Images from Docker Hub<\/a><\/h3>\n\n\n\n
Searching for Docker Images on Docker Hub<\/a><\/h4>\n\n\n\n
docker search<\/strong><\/code> command. The docker search command syntax is;<\/p>\n\n\n\n
docker search [OPTIONS] TERM<\/code><\/pre>\n\n\n\n
docker search --help<\/code><\/strong> to see more options.<\/p>\n\n\n\n
docker search hello-world<\/code><\/pre>\n\n\n\n
NAME DESCRIPTION STARS OFFICIAL AUTOMATED\nhello-world Hello World! (an example of minimal Dockeriz\u2026 1226 [OK] \nkitematic\/hello-world-nginx A light-weight nginx container that demonstr\u2026 147 \ntutum\/hello-world Image to test docker deployments. Has Apache\u2026 72 [OK]\ndockercloud\/hello-world Hello World! 19 [OK]\n...\n<\/code><\/pre>\n\n\n\n
\n
Pulling Docker Image to Local Registry<\/a><\/h4>\n\n\n\n
docker pull<\/strong><\/code> command or simply run it using
docker run<\/strong><\/code> command.<\/p>\n\n\n\n
docker search ubuntu<\/code><\/pre>\n\n\n\n
NAME DESCRIPTION STARS OFFICIAL AUTOMATED\nubuntu Ubuntu is a Debian-based Linux operating sys\u2026 11046 [OK] \ndorowu\/ubuntu-desktop-lxde-vnc Docker image to provide HTML5 VNC interface \u2026 441 [OK]\nrastasheep\/ubuntu-sshd\n...\n<\/code><\/pre>\n\n\n\n
docker pull ubuntu<\/code><\/pre>\n\n\n\n
Using default tag: latest\nlatest: Pulling from library\/ubuntu\na4a2a29f9ba4: Pull complete \n127c9761dcba: Pull complete \nd13bf203e905: Pull complete \n4039240d2e0b: Pull complete \nDigest: sha256:35c4a2c15539c6c1e4e5fa4e554dac323ad0107d8eb5c582d6ff386b383b7dce\nStatus: Downloaded newer image for ubuntu:latest\ndocker.io\/library\/ubuntu:latest\n<\/code><\/pre>\n\n\n\n
docker search ubuntu:20.04<\/code><\/pre>\n\n\n\n
List Available Docker Images<\/a><\/h4>\n\n\n\n
docker images<\/code> command.<\/p>\n\n\n\n
docker images<\/code><\/pre>\n\n\n\n
REPOSITORY TAG IMAGE ID CREATED SIZE\nubuntu latest 74435f89ab78 11 days ago 73.9MB\nhello-world latest bf756fb1ae65 5 months ago 13.3kB<\/code><\/pre>\n\n\n\n
Running a Docker Container Image<\/a><\/h4>\n\n\n\n
docker run<\/code> or
docker create<\/code> command.<\/p>\n\n\n\n
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
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG\u2026]<\/code><\/pre>\n\n\n\n
docker run -it ubuntu<\/code><\/pre>\n\n\n\n
root@43ff7a031a0b:\/#<\/code><\/pre>\n\n\n\n
docker run ubuntu cat \/etc\/os-release<\/code><\/pre>\n\n\n\n
NAME=\"Ubuntu\"\nVERSION=\"20.04 LTS (Focal Fossa)\"\nID=ubuntu\nID_LIKE=debian\nPRETTY_NAME=\"Ubuntu 20.04 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
Ctrl + p<\/strong><\/code> then
Ctrl + q<\/strong><\/code>.<\/p>\n\n\n\n
docker run -dit --name ubuntudemo ubuntu<\/code><\/pre>\n\n\n\n
docker attach ubuntudemo<\/code><\/pre>\n\n\n\n
Listing Docker Containers<\/a><\/h4>\n\n\n\n
docker ps<\/strong><\/code> command.<\/p>\n\n\n\n
docker ps<\/code><\/pre>\n\n\n\n
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n1c280cf21322 ubuntu \"\/bin\/bash\" 2 minutes ago Up 2 minutes ubuntudemo<\/code><\/pre>\n\n\n\n
docker ps -a<\/code><\/pre>\n\n\n\n
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\n1c280cf21322 ubuntu \"\/bin\/bash\" 3 minutes ago Up 3 minutes ubuntudemo\nb5453d11a544 ubuntu \"\/bin\/bash\" 10 minutes ago Exited (0) 8 minutes ago stupefied_hawking\na65d1797c504 ubuntu \"\/bin\/bash\" 14 minutes ago Exited (0) 12 minutes ago zen_ramanujan\nc4d68a2b1b39 ubuntu \"\/bin\/bash\" 23 minutes ago Exited (137) 20 minutes ago sweet_dirac\n9b7867c1daad ubuntu \"cat \/etc\/os-release\" 40 minutes ago Exited (0) 40 minutes ago great_allen\n<\/code><\/pre>\n\n\n\n
Start and Stop Docker Containers<\/a><\/h4>\n\n\n\n
docker start<\/strong><\/code> command. For example, to start container named, stupefied_hawking<\/strong>, with an ID of b5453d11a544<\/strong>, run the command;<\/p>\n\n\n\n
docker start stupefied_hawking<\/strong><\/code><\/pre>\n\n\n\n
docker start b5453d11a544<\/strong><\/code><\/pre>\n\n\n\n
docker stop<\/code> command.<\/p>\n\n\n\n
docker stop ubuntudemo<\/code><\/pre>\n\n\n\n
Removing Docker Containers<\/a><\/h4>\n\n\n\n
docker rm<\/strong><\/code> command.<\/p>\n\n\n\n
docker ps -a<\/code> output above;<\/p>\n\n\n\n
docker rm 9b7867c1daad<\/code><\/pre>\n\n\n\n
-f<\/strong><\/code> or
--force<\/strong><\/code> option of docker rm command.<\/p>\n\n\n\n
docker rm 1c280cf21322 -f<\/code><\/pre>\n\n\n\n
Removing Docker Images<\/a><\/h4>\n\n\n\n
docker rmi<\/code> 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
docker images -a<\/code><\/pre>\n\n\n\n
-q<\/strong><\/code> option.<\/p>\n\n\n\n
docker images -a -q<\/code><\/pre>\n\n\n\n
74435f89ab78\nbf756fb1ae65<\/code><\/pre>\n\n\n\n
docker rmi 74435f89ab78<\/code><\/pre>\n\n\n\n
docker rmi ubuntu<\/code><\/pre>\n\n\n\n
-f<\/strong><\/code> or
--force<\/code><\/strong> to force the deletion.<\/p>\n\n\n\n
Further Reading<\/h3>\n\n\n\n
Related Tutorials<\/h3>\n\n\n\n