Introduction
In the ever-evolving landscape of modern software development and deployment, Docker has become an indispensable tool. Docker provides a streamlined way to package, distribute, and manage applications within isolated containers. In this step-by-step guide, we will walk you through the process of how to install Docker Community Edition (CE) on Centos 7. By the end of this article, you’ll have a solid foundation to utilize Docker for optimizing your development and deployment workflows.
The main difference between container and VM(Virtual machine) is that dockers provide process based isolation, whereas VM provides full isolation of resources. Virtual machine takes a minute to start where as container can be started in a second or less than a second. Container uses the Kernel of host OS , whereas VM uses the separate Kernel.
Table of Contents
- Introduction
- Prerequisites
- Environment Specification:
- Step 1: Update Packages
- Step 2: Install Required Packages
- Step 3: Add Docker Repository
- Step 4: Install Docker CE
- Step 5: Start and Enable Docker
- Step 6: Verify Docker Installation
- Step 7: Run a Test Container
- Step 8: Manage Docker as a Non-Root User (Optional)
- Step 9: Additional Docker Configuration (Optional)
- Conclusion
Prerequisites
Before we dive into the installation process, make sure you have the following prerequisites in place:
- A CentOS 7 system with root or sudo access, to set this up, follow our guide Initial Setup CentOS 7 Server: Secure and Efficient You can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.
- A stable internet connection to download packages
- Basic familiarity with command-line operations.
Environment Specification:
We are using a minimal Rocky Linux 9 virtual machine with following specifications.
- CPU – 2 cores
- Memory – 2 GB
- Storage – 32 GB
- Operating System – Centos 7
- Hostname – docker-ce
Step 1: Update Packages
Start by updating your package list to ensure you have the latest information about available software:
[samm@docker-ce ~]$ sudo yum update
[samm@docker-ce ~]$ sudo yum upgrade
Step 2: Install Required Packages
[samm@docker-ce ~]$ sudo yum-config-manager --enable extras
[samm@docker-ce ~]$ sudo yum repolist
[samm@docker-ce ~]$ sudo yum install yum-utils device-mapper-persistent-data lvm2
[samm@docker-ce ~]$ sudo yum update -y
Step 3: Add Docker Repository
Add the official Docker repository to your system, which provides access to the latest Docker packages:
[samm@docker-ce ~]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
Step 4: Install Docker CE
Install the Docker Community Edition (CE) package using the following command:
[samm@docker-ce ~]$ sudo yum install docker-ce
Step 5: Start and Enable Docker
Start the Docker service and configure it to start automatically upon system boot:
[samm@docker-ce ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[samm@docker-ce ~]$ sudo systemctl start docker
[samm@docker-ce ~]$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Kam 2020-11-19 23:14:13 WIB; 5s ago
Docs: https://docs.docker.com
Main PID: 2219 (dockerd)
Tasks: 13
Memory: 41.9M
CGroup: /system.slice/docker.service
└─2219 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Step 6: Verify Docker Installation
Ensure that Docker has been successfully installed by checking its version:
[samm@docker-ce ~]$ docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:03:45 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:21 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
Step 7: Run a Test Container
To verify that Docker is functioning as expected, run a simple test container using the official “hello-world” image:
[samm@docker-ce ~]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[samm@docker-ce ~]$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
[samm@docker-ce ~]$ docker info
Client:
Debug Mode: false
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1127.19.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.7GiB
Name: viva-docker
ID: WCGK:IJJO:L3Q7:QWAS:2EFF:LAVN:FOPT:IYXX:C6SL:4BKG:YY37:GEAB
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Step 8: Manage Docker as a Non-Root User (Optional)
By default, Docker requires root privileges, but you can grant your user access to Docker commands without using sudo
. Add your user to the docker
group:
[samm@docker-ce ~]$ sudo usermod -aG docker $username
[samm@docker-ce ~]$ sudo chmod 666 /var/run/docker.sock
Log out and log back in, or run su - your_username
to apply the group changes.
Step 9: Additional Docker Configuration (Optional)
By utilizing Docker, you gain the capability to establish resource limits for containers, effectively managing their CPU, memory, and I/O utilization. This proactive approach ensures that containers refrain from overconsumption of resources, thus safeguarding the performance of other applications.
[samm@docker-ce ~]$ sudo vi /etc/sysctl.conf
Paste following line to file :
vm.max_map_count=262144
[samm@docker-ce ~]$ sudo sysctl -a
[samm@docker-ce ~]$ sudo reboot
Conclusion
Congratulations! You’ve successfully installed Docker CE on your CentOS 7 system. Docker’s containerization capabilities empower you to create isolated environments for your applications, making development, testing, and deployment more efficient and reliable. By following this comprehensive guide, you’ve gained the knowledge to set up Docker and run your first container. Docker’s advantages, such as consistency, scalability, and portability, will undoubtedly enhance your software development workflow. With Docker at your fingertips, you’re well-equipped to navigate the world of modern application deployment and take your projects to the next level.
Also Read Our Other Guides :
- How To Install and Use Docker Compose on Centos 7
- Install and Configure Docker Swarm Mode on Centos 7
- How To Install Docker CE on Rocky Linux 9
- How To Install and Use Docker CE on Ubuntu 22.04
Finally, now you have learned how to install Docker CE on Centos 7.