Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OnCloud125252/2346b1a03ce9d7fd378bfa26b083799f to your computer and use it in GitHub Desktop.
Save OnCloud125252/2346b1a03ce9d7fd378bfa26b083799f to your computer and use it in GitHub Desktop.
A step-by-step guide to installing Portainer, a Docker management tool, and configuring the MTU setting. Includes Docker installation, MTU issue fixes, permission error resolution, and Portainer deployment using Docker.

Before Starting

Supported Installation

Operating System Tool
Ubuntu Server 22.04 LTS Docker version 20.10.25, build 20.10.25-0ubuntu1~23.04.1, Portainer 2.18
Ubuntu Server 23.04 Docker version 20.10.25, build 20.10.25-0ubuntu1~23.04.1, Portainer 2.18

Installation

Install Docker

To configure the MTU properly, use Docker from apt instead of snap.
If you have already installed Docker through the system installation, remove the snap version of Docker first. Otherwise, skip this step.

Remove snap version of Docker:

sudo snap remove docker

Install Docker using apt:

sudo apt install docker.io

Fixing Docker MTU issue (Otional)

To specify/override the MTU for Docker, add a parameter to the Docker launch script. The file to edit is /lib/systemd/system/docker.service.

If you're unsure which is the correct file, you can find it using the following command:

sudo systemctl status docker

Look for the line that starts with Loaded: and find the path after loaded. This is the file you're looking for.

To change the MTU setting (for example, to 1400), modify the line in /lib/systemd/system/docker.service from:

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

to:

ExecStart=/usr/bin/dockerd --mtu 1400 -H fd:// --containerd=/run/containerd/containerd.sock

If you're using docker-compose to launch your instances, you also need to change some configuration to ensure they launch with the specified MTU.

Your Docker Compose file should include the following section:

networks:
  default:
    driver: bridge
    driver_opts:
      com.docker.network.driver.mtu: 1400

After making these changes, restart Docker to apply the new MTU setting:

sudo systemctl daemon-reload
sudo service docker restart

Fixing Docker permission error

If you encounter a permission error like the following when executing docker commands:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

You can either run docker commands with sudo, or enable a non-root user to access the docker command by following these steps:

  1. Create the docker group on the system:
    sudo groupadd -f docker
  2. Add the active user to the docker group:
    sudo usermod -aG docker $USER
  3. Apply the group changes to the current terminal session:
    newgrp docker
  4. Check if the docker group is in the list of user groups.
    groups
    The group should appear in the command output.
    image
    You should now be able to issue Docker commands as a non-root user without using sudo.

Install Portainer

First, create the volume that Portainer Server will use to store its database:

docker volume create portainer_data

Then, download and install the Portainer Server container:

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

Finishing

Now that the installation is complete, you can log into your Portainer Server instance by opening a web browser and going to https://localhost:9443.
Once you have accessed the Portainer Server URL, you are ready to proceed with the initial setup.

For detailed instructions on the initial setup, please refer to the official setup tutorial.

If you encounter an issue accessing the Portainer panel and see the error message shown below, it is likely because Portainer shuts down internally for security if a new installation is not configured within 5 minutes:
image
You can resolve this issue by running the following command to restart Portainer:

docker restart portainer

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment