One of my biggest challenges of owning an Ubuntu VPS has been managing applications that I installed into server. Having applications with different version requirements of the same libraries or frameworks has always resulted in me spending many hours resolving conflicts and a messy server filesystem. To resolve this issue, I decided to containerise my server with docker so that all this applications can co-exist without interfering with each other and when it comes to zapping time it will be done easily by deleting the unwanted container(s).
Having containers in my server solved one problem and created another one. Managing containers from CLI is quite cumbersome I needed a better way of doing this preferably on a graphical interface and thats when I came across Portainer. I liked Portainer because its light weight, easy to use and I can access it remotely over the web.
The section below show procedures I took when setting up my server
What is Portainer?
Portainer is management toolset that allows easy building, managing and maintaining Docker environments. Portainer enables you manage your Docker containers from a web based graphical interface, thus making it easy to manage containers for persons who are not comfortable with Docker and/or Linux CLI.
In this blog post we are going to focus on Portainer Community Edition and how to install it an Ubuntu 18.04 box.
Portainer runs in a container, so we need to install and have Docker service running in our server. Installing docker is quite easy and straight forward especially if you are used to the linux environment. First we start by making sure our server is up to date by running the following commands.
# sudo apt update # sudo apt upgrade
The first command checks Ubuntu repos for updates and updates local repo sources, the second command will install the updated packages.
With Ubuntu up to date, the next step is to install Docker CE.
By default, the latest version of Docker is not available in the Ubuntu 18.04 server default repository. To get the latest version we need to install Docker from the official Docker repository. To do that, we’ll add the official Docker repository to our package manager list by running the three commands below:-
- Install prerequisite packages which let apt use packages over HTTPS
# sudo apt install apt-transport-https ca-certificates curl software-properties-common
2. Add Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3. Activate Docker repository and update it
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # sudo apt update
Finally, install Docker
# sudo apt install docker-ce
To verify Docker is up and running after installation we can check it status by running the command below
# sudo systemctl status docker
You should get an output like the one displayed below, showing the service is up and active
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-03-03 09:57:11 UTC; 23s ago Docs: https://docs.docker.com Main PID: 18005 (dockerd)...
With our docker environment setup done, it’s time to finally deploy Portainer. To deploy Portainer into your service run the commands below
# docker volume create portainer_data # docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
The first command create a volume in your files system where Portainer will be persisting data and the second commands creates a container from a Portainer image and starts it with the given commands like in this case :- listen on external port 9000 which is linked to internal port 9000 and use portainer_data volume
To check the status of your container, run the command below
# sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a21510321870 portainer/portainer "/portainer" 21 hours ago Up 2 hours 0.0.0.0:9000->9000/tcp portainer
The image is up and running and can be accessed on port 9000. Go to your browser and browse to http://<local_ip or public_ip>:9000 to see the Web interface where you can continue with the setup process as below.
Setup your admin account
Connect Portainer to your local Docker environment
Portainer Dashboard showing local Docker environment. Click on the local to proceed.
A summary of images, containers and networks deployed in the environment.
Containers can be created from App Templates, Stacks or Images and Containers.