Welcome to my website

Setup Docker, Docker-compose and portainer

Guide: Installing Docker, Docker Compose, and Portainer CE



This guide will walk you through setting up Docker Engine, Docker Compose, and Portainer Community Edition (CE) on your Linux server. This powerful combination allows you to easily run, manage, and monitor containerized applications.

Prerequisites:
  • A Linux server (e.g., Ubuntu, Debian)
  • Root access or sudo privileges
  • Internet access for downloading packages


Step 1: Install Docker Engine
When installing Docker on Ubuntu/Debian, there are two common approaches:
  • Using Ubuntu's default repositories (via the `docker.io` package): This is simpler to install, but the versions provided are often older and not updated as frequently. You might miss out on the latest features, bug fixes, or security patches.
  • Using Docker's official repositories (via the `docker-ce` package): This method provides the very latest stable releases directly from Docker, with more frequent updates and all the newest features. This is generally the recommended way to install Docker for most users.

This guide focuses on installing Docker from its official repositories to ensure you get the most up-to-date and fully supported version of Docker.

1. Update your package index and install dependencies:

sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release


2. Add Docker's official GPG key:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg


3. Set up the stable Docker repository:

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


4. Install Docker Engine, CLI, Containerd, and Compose Plugin:

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


5. Verify Docker installation:

sudo docker run hello-world

You should see a message indicating Docker is working correctly.

6. Add your user to the 'docker' group (Optional, but Recommended):
This allows you to run Docker commands without `sudo`. Replace $USER with your actual username if it's different from the current logged-in user.

sudo usermod -aG docker $USER

Note: You will need to log out and log back in (or restart your terminal session) for this change to take effect. After logging back in, you can test by running `docker run hello-world` without `sudo`.

Step 2: Verify Docker Compose Installation
The `docker-compose-plugin` installed in Step 1 provides Docker Compose functionality.

Verify Docker Compose is working:

docker compose version

You should see output similar to `Docker Compose version v2.x.x`. Note the space between `docker` and `compose` (it's a plugin).

Step 3: Install Portainer CE (Community Edition)
Portainer CE is a powerful, user-friendly UI for managing your Docker environments.

1. Create a Docker volume for Portainer data:
This volume will persist Portainer's data (settings, configurations) even if the container is removed or updated.

docker volume create portainer_data


2. Run the Portainer CE Docker container:
This command downloads the Portainer image and runs it as a 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

  • -d: Run the container in detached mode (in the background).
  • -p 8000:8000 -p 9443:9443: Map host ports 8000 and 9443 to the container's ports. Port 9443 is for the secure web UI, 8000 is for edge agent communication (can be removed if not needed).
  • --name portainer: Assign a name to the container for easy identification.
  • --restart always: Ensures Portainer starts automatically when Docker starts.
  • -v /var/run/docker.sock:/var/run/docker.sock: Mounts the Docker socket, allowing Portainer to manage the Docker host.
  • -v portainer_data:/data: Mounts the named volume for persistent data.
  • portainer/portainer-ce:latest: The Docker image to use.


3. Configure Firewall for Portainer (If Active):
If you have a firewall, you'll need to open the Portainer web UI port (9443).

sudo ufw allow 9443/tcp
sudo ufw reload


4. Access the Portainer Web UI:
Open your web browser and navigate to https://your_server_ip_or_domain:9443.
  • You might encounter a browser warning about an insecure connection because Portainer uses a self-signed SSL certificate by default. You can safely proceed past this warning.


5. Initial Portainer Setup:
The first time you access Portainer, you will be prompted to create an administrator user.
  • Create a strong username and password for your Portainer admin account.
  • Once logged in, select 'Local' environment to connect to the Docker instance on your current server.


Conclusion
You now have Docker Engine, Docker Compose, and Portainer CE installed and running on your server. You can use Portainer's intuitive web interface to manage your Docker containers, images, volumes, and networks, making containerization much easier!

Back to Knowledge Base