Setting Up Docker on CentOS 7.4 VPS
Overview
Docker is a contemporary container-based technology that leverages cgroups and namespaces in the Linux environment. Unlike traditional virtualization, Docker operates as software, adding an additional isolated layer within the host OS. With Docker, you can run multiple instances of containers, each fulfilling its own role. This technology streamlines deployment, installation, migration, and maintenance processes for applications. In this guide, I will walk you through the installation of Docker on your VPS, demonstrate how to pull a Docker image containing a specific application, and verify its performance.
Requirements
CentOS 7.4 VPS instance
Basic Linux skills including package installation, file editing, and service control.
Installation
There are two branches of Docker: Enterprise Edition (EE) and Community Edition (CE). For development purposes and in most cases, the Community Edition is sufficient. However, if you plan to use Docker in a high-scale commercial production environment and require support, consider opting for the Enterprise Edition. Docker is available through the official repositories of CentOS and the upstream official repository. I recommend using the upstream repository as it is regularly updated and well-maintained. Below is the process for installing the Community Edition of Docker from the upstream official repository: Docker CE for CentOS[1].
1. Confirm that you do not have any old Docker version installed by running:rpm -qa | grep docker
Check and confirm that you have no other Docker packages installed, especially from the CentOS repository. If you find any, and you haven’t installed them intentionally, remove them using:yum remove <package_name>
If you share the VPS server with others, it’s advisable to consult with them to ensure you do not unintentionally remove someone else’s work.
2. Set up the upstream Docker repository by running the following commands: wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
Confirm that the repository was added properly by running:
yum repolist
Your output should show the new docker-ce repository and the available versions.
3. install docker-ce package
yum install docker-ce
4. Start the Docker process and confirm that it has started without any problems.
systemctl start docker
systemctl status docker
The status should display no errors.
5. Confirm that your Docker installation works as expected by running the following command:
Pull a container image that you will use for experimentation. By default, Docker Hub includes a variety of images, some containing a system with specific applications deployed, while others are base system images. Docker allows you to search for images using the command docker search
. Just add a search argument, for example, docker search ansible
or docker search centos
, and check the output. Let’s pull the Ubuntu image with the SSH service:
docker search sshd
Pull the top-rated Ubuntu image by executing the following command:
docker pull rastasheep/ubuntu-sshd
Verify that the Ubuntu image is now available locally by running the following command:
docker images
Here is information about this container: rastasheep/ubuntu-sshd[2]
PermitRootLogin yes
UsePAM no
exposed port 22
default command: /usr/sbin/sshd -D
root password: root
7. Let’s start this container and check its availability
docker run -d -P --name ssh_test rastasheep/ubuntu-sshd
Check which host port is forwarded to port 22 inside the container
docker port ssh_test 22
And now try connecting to this instance from a remote PC to ensure that it is indeed running Ubuntu.
It’s evident that we can establish a connection to our Docker instance from an external machine, and it’s confirmed that the instance is running Ubuntu inside.
In Summary
You’ve gained valuable insights into installing Docker on your VPS server and experienced a fundamental Docker container scenario. This sets a solid foundation for exploring more advanced Docker features and deploying applications or services in isolated instances. If you have further questions or if there’s anything specific you’d like to delve into within the realm of Docker or any other topic, feel free to ask!
[1]: https://hub.docker.com/editions/community/docker-ce-server-centos
[2]: https://github.com/rastasheep/ubuntu-sshd