Skip to content

Docker, Docker-Compose, and Portainer-CE Setup

Powered by Ghost
Docker

Table of Contents
Introduction
Docker and Docker Compose Installation
Portainer-CE Installation

Introduction

In this Tutorial we are going to walk through the setup process of Docker, Docker Compose, and Portainer-CE, on a FRESH install of Ubuntu ( In my case I use Ubuntu 22.04 ) since we have been doing a bunch of tutorials that were using Docker Compose. Docker for Ubuntu will work on any of the following versions of 64-bit Ubuntu

  • Ubuntu Mantic 23.10
  • Ubuntu Lunar 23.04
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)

Docker Engine for Ubuntu is compatible with x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el) architectures.

Docker and Docker Compose Installation

Before we install docker make sure you remove any previous or unofficial versions of docker possible installed on the system (Even fresh installs may install a different version of docker.)

Run the following command to remove all possible conflicts.

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

apt-get might report that you have nothing installed. That is a good thing. Once everything has been completed continue to the next step.

It's now time to setup our apt repository for Docker, to do this start by running the following command to update your Ubuntu Install... this should go quick if you did updates while installing Ubuntu.

sudo apt-get update && sudo apt-get upgrade -y

Once you have completed updates and upgrade, you are ready to run the following commands.

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

Then run the following command to add the repository

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

Now your ready to update your apt repository.

sudo apt-get update

Time to install Docker and test it using the hello-world test image.

To Install the latest Docker version, run:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

After installation is finished run the following command to make sure everything is working.

sudo docker run hello-world

Once that is done, the next step is to give the regular user access to docker.

(WARNING: The docker Group grants root-level privileges to any user asigned to the group.)

There is two ways to do this, Today we are going to go with the easy way but the Docker website dose provide a way to run Docker in Rootless mode, if you'd like to do this please Follow This Link

To get started create the docker group and add the user:

  1. Create the group
sudo groupadd docker
  1. Add your user to the group
sudo usermod -aG docker $USER
  1. Log out and log back in or use the command newgrp docker to refresh your changes (According to the Docker Docs, If your Running Linux in a virtual machine, Linux may require to you RESTART the virtual machine for changes to take effect.)
  2. If Everything Worked, You should now be able to use the following command without the sudo command needed.
docker run hello-world

If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error:

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied

This error indicates that the permission settings for the ~/.docker/ directory are incorrect, due to having used the sudo command earlier.

To fix this problem, either remove the ~/.docker/ directory (it's recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R

sudo chmod g+rwx "$HOME/.docker" -R

You should no longer see the Error, and Docker and Docker Compose is now installed.

Time to move on to Portainer-CE

Portainer-CE Installation

Portainer consts of two parts, The Server and the Agent. Both run as lightweight Docker containers on a Docker engine. To start you need the server Installation. So we will focus on that. By Default, Portainer Server will expose the UI over 9443 and expose a TCP tunnel server over port 8000 the latter is optional and is only required if you plan to use the Edge compute features with Edge agents.

Now, Lets get started. First we need to create a volume for Portainer to store its database:

docker volume create portainer_data

Then run the following command to Download and Install the Portainer Server container:

docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

The above command will start a Portainer Server with the following Ports available:

  • 8000: Edge Connections (Optional)
  • 9000: WebUI HTTP (Optional)
  • 9443: HTTPS Self-Signed SSL by Default

You can now login either by http://SERVER-IP:9000 or https://SERVER-IP:9443

Then Continue with Portainer inital setup by Creating the first user, and you now have a functioning Portainer install. You may need to set your install to use the Local standalone environment, but it walks you through that process.

Here are some useful portainer stacks that I use in my own Portainer installs. Just copy the contents of a specific YML and paste it into the stack creator:

GitHub: Docker Compose/Portainer Scripts