Skip to main content
  1. Posts/

Docker & Portainer

·492 words·3 mins
CoeusLabs
Author
CoeusLabs
Passionate self-hosting enthusiast sharing insights and experiences in homelab deployment and Linux. Not a professional, but always eager to learn and help others.
Table of Contents

What is it and why?
#

To begin, almost everything I deploy will be in the form of a Docker container or stack. To simplify this process, we’ll use Portainer, a GUI for Docker. Docker is a tool that allows you to create containers, or groups of containers (stacks), which act as lightweight operating systems designed to run specific applications, such as websites.

Interestingly, Portainer itself is a Docker container, making it easy to deploy and use. We’ll deploy Portainer using the Docker CLI tool so you can get some hands-on experience with it before jumping to Portainer.

Deployment
#

It’s quite simple and only requires a few steps. Just a reminder: all commands, including apt and docker, need sudo privileges to work. You can either prefix these commands with sudo or run sudo su to become the root user during the installation process.

Docker
#

First, check if Docker is already installed with the command docker --version. If the output is a version number, Docker is installed, and you only need to ensure it’s up to date. If the output is an error, Docker isn’t installed, and you can follow this tutorial for a simple installation on Ubuntu. If you’re using another OS, select the appropriate tutorial from the menu in the link provided.

Portainer
#

Once Docker is installed and ready, it’s time to install Portainer. You can follow the official guide or simply run the commands below. I’ll explain them briefly.

First, create a Docker volume for Portainer to store its data by running:

docker volume create portainer_data

Then, deploy the Docker container with the following command:

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

Here’s what’s happening in this command:

  • -d runs the container in the background. Without this, the container would be tied to the current shell and terminate when the shell is closed.
  • -p maps the machine’s ports (left of the colon) to the container’s ports (right of the colon). For example, 8000:8000 binds the machine’s port 8000 to the container’s port 8000.
  • --name assigns a name to the container.
  • --restart=unless-stopped ensures the container restarts automatically unless it was manually stopped.
  • -v mounts volumes. The first volume mounts the Docker socket of the machine to Portainer so it can manage Docker containers. The second volume mounts the previously created Portainer data volume.

That’s all! Portainer is now running on your server. You can check if the Portainer container is running by using the command docker ps. The output should look something like this:

root@server:~# docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED       STATUS      PORTS                                                                                  NAMES             
de5b28eb2fa9   portainer/portainer-ce:latest  "/portainer"             2 weeks ago   Up 9 days   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp   portainer

Now, open a web browser and go to:

https://server_ip:9443

You will be greeted with the initial setup. Once you complete it, managing your Docker containers becomes much easier.

The End
#

That’s all for this time. I hope it helped you.