Setting up a Docker instance on your CentOS 7.4 VPS

Introduction

Docker is considered to be a modern container-based technology, that utilizes a cgroups and namespaces Linux technology. In fact, it's not a virtualization technology, but a software to add an additional isolated layer inside the host OS. You can run multiple instances of such containers, each container fullfilling it's own role. It has a lot of features, that make deploy, installation, migration and maintenance of your application a much easier process. In this guide i will describe how to install docker on your VPS, how to pull an image with a specific application inside and check that it performs as expected.

Preprequisites

1) Centos 7.4 VPS instance 2) Basic Linux skills ( package installation, file editing, service control )

Installation

There are two branches of Docker: Enterpise Edition ( paid edition ) and Community Edition. For development purposes, and most cases, Community Edition is good enough, however if you consider using docker in high-scale commercial production environment, and require support, consider using Enterprise Edition. There are also two ways of obtaning docker: Centos official repository and upstream official repository. I prefer, and recommend to use upstream repository, since it is up to date, in sync and generally maintained well. I will describe a process of installation a Community Edition docker from upstream official repository. https://store.docker.com/editions/community/docker-ce-server-centos[1] 1) Confirm that you do not have any old docker version run rpm -qa |grep docker

and confirm that you have no other docker packages installed, for example from Centos repository. If you have them, and do not know where did you get them from, you have never installed them, and you know that you do not user docker remove them with yum remove <docker package names> If you share VPS server with someone, and it may be used by someone, better consult with them, to ensure you do not remove someone's valuable work :)

2) setup an upstream docker repository run wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

confirm that repo was added properly

yum repolist

your output should show new docker-ce repository docker ce 1

3) install docker-ce package

yum install docker-ce

4) start the docker process and confirm that it have started without a problem

systemctl start docker

systemctl status docker

Status should display no error enter image description here

5) Confirm that your docker installation works, as expected run docker run hello-world You should get a similar output, that speaks for itself enter image description here

6) Pull a container image, that you will use to expriment By default docker hub includes a lot of different images, some of them contain a system with some application deployed, some are just some system images. docker allows to search for images using special coommand 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 sshd service

docker search sshd

docker sshd images Let's pull the top rated image

docker pull rastasheep/ubuntu-sshd

docker pull

Check that image is now available locally

docker images

docker images

Here is info about this container: https://github.com/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 that it is available

docker run -d -P --name ssh_test rastasheep/ubuntu-sshd

Check what host port is forwarded to 22 port inside the container

docker port ssh_test 22

enter image description here And now try connecting to this instance from a remote pc and check that is is really ubuntu enter image description here We clearly see that we can connect to our docker instance from the external machine, and that it is running ubuntu inside.

Conclusion

You now know how to install Docker on your VPS server and a basic docker container scenario usage. In our case you have an isolated instance inside our VPS server, that can be used for different purposes. This is only a glimpse into all the features that Docker provides, however you now have a good base to start dockerising your applications or services.

[1]: https://hub.docker.com/editions/community/docker-ce-server-centos
[2]: https://github.com/rastasheep/ubuntu-sshd