- Published at
Deploying Portainer with Docker: A Practical Guide
Learn how to deploy Portainer, a web UI for managing Docker containers, using a single Docker command. This guide provides clear instructions and explanations for intermediate learners.
- Authors
-
-
- Name
- James Lau
- Indie App Developer at Self-employed
-
Table of Contents
Introduction
Portainer is a powerful web UI that simplifies the management of your Docker environment. It allows you to easily view, manage, and monitor containers, images, networks, volumes, and more – all through a user-friendly interface.
This blog post will guide you through deploying Portainer using a single docker run command. We’ll break down each part of the command so you understand what it does and why it’s important.
The Docker Run Command
The following command deploys Portainer:
docker run -d -p 9000:9000 -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
Let’s dissect this command:
docker run: This is the core Docker command to create and start a container.-d: Runs the container in detached mode, meaning it runs in the background. You can continue using your terminal without being attached to the container’s output.-p 9000:9000 -p 8000:8000 -p 9443:9443: These are port mappings. They map ports from the host machine (your computer) to ports inside the container.9000:9000: Maps Portainer’s web UI on port 9000 within the container to port 9000 on your host. You’ll access Portainer in your browser athttp://localhost:9000.8000:8000: Maps Portainer’s API on port 8000 within the container to port 8000 on your host.9443:9443: Maps Portainer’s secure web UI on port 9443 within the container to port 9443 on your host. You’ll access it athttps://localhost:9443. Note that you might need to configure SSL certificates for this to work properly.
--name portainer: Assigns a name (portainer) to the container, making it easier to manage and refer to later.--restart=always: Configures the container to automatically restart if it crashes or the system reboots. This ensures Portainer is always available.-v /var/run/docker.sock:/var/run/docker.sock: This creates a volume mount. It mounts the Docker socket (/var/run/docker.sock) from your host machine into the container. The Docker socket allows Portainer to communicate with and manage the Docker daemon on your host.-v portainer_data:/data: Creates another volume mount, this time using a named volumeportainer_data. This volume persists data related to Portainer (like user accounts, configurations) even if the container is stopped or removed. This prevents you from losing your settings each time.portainer/portainer-ce:latest: Specifies the Docker image to use for creating the container. In this case, it’s the official Portainer Community Edition (CE) image with thelatesttag.
Accessing Portainer
Once the command completes successfully, you can access Portainer in your web browser at http://localhost:9000. The first time you access it, you’ll be prompted to set a password for the administrator user. Remember this password!
Conclusion
Deploying Portainer with Docker is straightforward using this single command. Understanding each part of the command allows you to customize your deployment and troubleshoot any issues that may arise. Portainer provides a valuable web UI for managing your Docker containers, making it an essential tool for developers and system administrators.