In this tutorial, we will show you how to install Docker on a CentOS 7 VPS.
Docker is a software development platform which makes it easy and simple to run applications in a container. It’s a kind of virtualization technology that makes it simple to develop and deploy applications inside of neatly packaged virtual containerized environments. Docker containers can be deployed to any machine without any compatibility issues, so the software stays system agnostic, simpler to use, less work to develop, and easy to maintain and deploy. Let’s begin the installation.
- For the purposes of this tutorial, we will use a CentOS 7 VPS.
- Full SSH root access, or a user with sudo privileges is also required.
Step 1: Connect via SSH
Connect to your server via SSH as the root user using the following command:
ssh [email protected]_ADDRESS -p PORT_NUMBER
and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.
Before starting with the installation, you will need to update your system packages to their latest versions.
You can do this by running the following command:
sudo yum update
Once the update is completed, we can move onto the installation step.
Step 2: Install Docker on CentOS 7
The recommended way to install Docker is to install from the Docker repositories. We will install some required dependencies with the following command:
sudo yum install yum-utils device-mapper-persistent-data lvm2
Next, we will add the Docker repository, enable it, and install it with the following commands:
sudo yum-config-manager --add-reposudo yum install docker-ce
After the installation has completed, we will start the Docker daemon:
sudo systemctl start docker
We can verify that it’s running with the following command:
sudo systemctl status docker
The output should be similar to the following:
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) Docs:Main PID: 4234 (dockerd) Tasks: 8 CGroup: / └─4234 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/
Docker has now been successfully installed. In the next steps, we will show you how to use the docker command.
Step 3: Using the Docker Command
The syntax of the Docker CLI command takes this form:
docker [option] [command] [arguments]
To list all available commands, we need to run the docker command with no parameters:
The output should be similar to the following:
A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -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 "/root/.docker/") --tlscert string Path to TLS certificate file (default "/root/.docker/ ") --tlskey string Path to TLS key file (default "/root/.docker/ ") --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 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
To see the options available to a specific command, execute the following command:
docker docker-subcommand --help
To view information about Docker:
Step 4: The Docker Command Line Interface
To search for an image from the Docker Hub registry, we can use the following command:
docker search centos
If you want to download an official copy of CentOS 7, we can do this by using the image pull subcommand:
docker image pull centos
If there is no tag specified, Docker will pull the latest image.
We can list the images by using the following command:
docker image ls
If you need to remove an image for any reason, you can use the following command:
docker image rm centos
To start, stop, remove, and manage a container, you can do this with the following subcommand:
With the following command, we can start a Docker container:
docker container run centos
If you need to interact with the container via the command line, you can do this executing the following command:
docker container run -it centos /bin/bash
To list all active containers, type:
docker container ls
You can view both active and inactive containers with the following line:
docker container ls -a
To remove docker containers, execute the following command:
docker container rm [container_id]
Those are some of the most useful commands for Docker. In this tutorial, we learned how to install Docker on Centos 7 and how to use the docker command line interface.
Of course, you don’t have to install Docker on CentOS 7 if you use one of our Managed CentOS Hosting services, in which case you can simply ask our expert system administrators to install Docker on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Docker on CentOS 7, please share it with your friends on the social networks by using the share shortcuts below, or simply leave a comment in the comments section. Thanks.