Install Docker and Portainer on Ubuntu
In this article I will cover how to install Docker and Portainer on Ubuntu server.
First thing is to ensure your system is fully updated. Run:
sudo apt update && sudo apt upgrade
This will ensure your system is running the latest packages. Docker actually has decent installation instructions which can be found here.
However I’ll go over it (but you should reference the official docs if something isn’t working). Run each of these commands separately:
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Docker is now installed. Pretty uneventful right? There is one last command, however it’s optional. It will allow running docker commands without sudo. This isn’t a hard requirement (read more here), but I usually do it:
sudo usermod -aG docker $USER
It may not seem like it, but docker is already running on your host. I love the CLI but Portainer such a cool GUI for Docker that it’s always the first thing I install. The official docs are here. I will cover the installation, which is quite simple.
First, create a volume for Portainer (remember to add sudo if you didn’t add yourself to the docker group):
docker volume create portainer_data
Then run the docker command for Portainer:
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
By reading the command you can see that we are running a docker image using ports 8000 and 9443, its named ‘portainer’, it will always restart, it is using two volumes, and it will use the latest version of portainer.
If you are running Ubuntu server, you don’t have a browser to open Portainer in, so using another PC on your network you can open up portainer by typing in the IP of your host and using port 9443. If you are running Ubuntu Desktop you can simply open a browser and navigate to localhost:9443.
https://localhost:9443
On your first load, you will setup a username and password. Make sure to keep this handy. You can reset your password if needed though, its just a pain.
Once Portainer is up, you can click “Get Started” to use the local environment. You can still use the command line if you want, but you also now have the option to manage your docker containers through portainer. You can even use stacks to deploy multiple containers which make running a suite of containers even easier.
In the next article few articles, I will cover how to add some monitoring to your host with Grafana, Prometheus, cAdvisor and Node Exporter. This will give you an easy way to monitor your system resources and docker containers.