How to install Docker on a VPS or VDS server
Docker is a software platform for building and launching Linux containers. As a technology, containerization allows kernel processes to be isolated, ultimately making the virtual environment think that each container is the only process running on the server.
While Docker sounds very similar to virtual machines in terms of how it works, the 2 are quite different. With Docker, all containers share the same kernel, while every virtual machine (VPS/VDS) has its own individual kernel with the exception being OpenVZ-based VPS servers, where the virtual machine is a container in itself.
What do I need to install Docker?
Before you can install the software, you are going to need to get a Linux-based server, preferably one running Debian, Ubuntu or CentOS.
How to install Docker on a cloud server
Installing Docker on a cloud server is very easy. First, you need to connect to your server via SSH with a privileged (root) user.
Next, you will need to update the package list for your server. You can do so with the following command:
Once your packages have been updated, you will need to run this command:
curl -sS https://get.docker.com/ | sh
This script will automatically detect your operating system, install all of the required packages and also install Docker.
IMPORTANT: If you don’t have curl installed on your server, you can install it using this command:
apt-get install curl
yum install curl
If you have just installed curl, you will need to run the docker install command again.
How can I test my installation?
Once the installation concludes, you can test whether everything has been installed with the help of a hello-world image.
To perform this test, simply run this command:
docker run hello-world
If everything has been successfully installed and is working properly, you should see this output:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d 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/
Extra post-installation tips
Here are some additional post-installation suggestions for Docker that you can benefit from.
Non-root access to Docker
Currently, you should be logged into the server via a root user, which will allow you to manage Docker. If you wish to use Docker with a non-root user, you’d need to use sudo every time you want to use the application.
Instead, we can give non-root access to the docker management commands by typing these commands into the console:
groupadd docker usermod -aG docker YOUR_USER
This will automatically set up access and you will not have to use sudo every time you want to make changes.
Configure Docker to start with the OS
Making sure that Docker starts along with the operating system will make sure that the software and all Docker containers will start automatically, which can be very useful if you are going to be rebooting your OS.
You can do that by running this command:
systemctl enable docker
If you need assistance installing Docker on your VPSBG server, please do not hesitate to contact us.