The information technology field is running so fast, made the companies and all parties involved must adapt quickly. This condition drives many developers to develop their applications to be more flexible and can be portable to various types of environments. Docker is an application that makes it simple and easy to run application processes in a container. A container itself is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. In this article, we ’ll learn How To Install Docker Community Edition (CE) on CentOS 7.
The Docker installation method will be using an existing installation of the operating system. After installation was completed done, we will continue to use Docker installed for setting up new imange. The Docker installation on CentOS article will be divided up to several sub-topic as below :
Before we are going through the steps of installing Docker on CentOS 7, we have to setup the Docker requirement :
- 64-bit CentOS 7 Operating System, Docker requires a 64-bit version of CentOS 7 as well as a kernel version equal to or greater than 3.10. The default 64-bit CentOS 7 Droplet meets these requirements
- Non-root user with sudo privileges.
The Docker package has been available in the official CentOS 7 repository, but it may not always be the latest version. The recommended approach is to install Docker from the Docker’s repositories. Docker installation steps will be described details below.
Updating CentOS system packages
[ramans@localhost ~]$ sudo yum update
Install Docker from Docker Repository
Download the latest version of Docker from Docker official web site, and install it.
[ramans@localhost ~]$ curl -fsSL https://get.docker.com/ | sh
Start Docker daemon
After Docker package is installed, start the Docker daemon.
[ramans@localhost ~]$ sudo systemctl start docker
Enable Docker Services
After restarting the Docker service and no error found, the next step is to enable Docker daemon to automatically start at boot time.
ramans@localhost ~]$ sudo systemctl enable docker
Verify Docker Installation
To verify that the Docker service is running type:
[ramans@localhost ~]$ sudo systemctl status docker
Checking Docker Version
When this article was written the Docker last stable version is 19.03.5 which was released on November 13, 2019. to verify the Docker version is by issuing the command :
[root@localhost ~]# docker version
Administering Docker is requiring root/administrator privilege, but we can run Docker commands as a non-root user without prepending
sudo. We have to add our user to the Docker group which is created during the installation of the Docker CE package. You can do that by typing: (my user name is ramans).
sudo usermod -aG ramans
We have to log out and log back in so that the group membership is refreshed. To verify we can run docker commands without sudo, issue the following command which will download a test image, run in a container, print a “Hello from Docker” message and exit:
[ramans@localhost ~]$ docker container run hello-world Hello from Docker! This message shows that your installation appears to be working correctly.
Docker command line interface
We could list all available subcommands on Docker as below.
[ramans@localhost ~]$ docker Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/home/ramans/.docker") -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") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/home/ramans/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/home/ramans/.docker/cert.pem") --tlskey string Path to TLS key file (default "/home/ramans/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers context Manage contexts engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
The How To Install Docker Community Edition (CE) on CentOS 7 will be continue in other article for discussion how to use the Docker and whats is the positive impact for development stage.
- Objects: Docker objects are various entities used to assemble an application in Docker. The main classes of Docker objects are images, containers, and services.
- A Docker container is a standardized, encapsulated environment that runs applications. A container is managed using the Docker API or CLI.
- A Docker image is a read-only template used to build containers. Images are used to store and ship applications.
- A Docker service allows containers to be scaled across multiple Docker daemons. The result is known as a swarm, a set of cooperating daemons that communicate through the Docker API.
At our system, the Docker’s images can be listed by using command
docker images, the result are as below :
[ramans@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE finid/centos-mariadb latest a74bf935cc62 3 days ago 479MB centos latest 0f3e07c0138f 2 months ago 220MB hello-world latest fce289e99eb9 11 months ago 1.84kB
Docker Container is An instance of an image. A container represents a runtime for a single application, process, or service. The Docker Container can be called with command
docker container run -it <REPOSITORY_LIST>. At this example we are going to use the MariaDB images that we have pulled to the our Docker images, as stated above.
[ramans@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE finid/centos-mariadb latest a74bf935cc62 3 days ago 479MB centos latest 0f3e07c0138f 2 months ago 220MB hello-world latest fce289e99eb9 11 months ago 1.84kB [ramans@localhost ~]$ docker container run -it finid/centos-mariadb [root@19d5cb1c111d /]# mysql -u root
So far, the article of ‘How to Install Docker Community Edition (CE) on CentOS 7’ is completed, I am going to write another article about Docker in the future. Thank you and have a nice day !
Note : the Docker Logo is property of Docker, Inc.