When you have eliminated the impossible, whatever remains, however improbable, must be the truth, Sherlock Holmes.
Portainer is a container management platform that provides a user-friendly interface for deploying, managing, and monitoring containerized applications —especially those running on Docker or Kubernetes.
This is the second post in our Portainer series, building on Deploying Portainer on Proxmox LXC. It is highly recommended that you read our first post, Deploying Portainer on Proxmox LXC: Script-Driven & GUI Walkthrough.
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, e.g., https://192.168.1.40:9443 (or your container’s IP). On first load, create an admin user and secure the instance.
In Portainer, a Stack refers to a Docker Compose setup that allows users to manage multiple containers as a single application. This simplifies the deployment and management of applications that consist of multiple services.
To create or deploy a new stack, follow these steps:
To begin using Portainer, select the Get Started button to go to the Portainer dashboard. It provides a summary of all environments you have added to Portainer. Initially, you will see a local environment.
Each environment is represented by a summary tile that displays:
Running Containers: The number of containers currently active.
Stopped Containers: The number of containers that are not running.
Healthy Containers: The count of containers that are operating without issues.
Images Available: The total number of Docker images stored in the environment.
Volumes Available: The count of data volumes created for persistent storage.
This summary provides quick insights, allowing you to monitor the health and status of your Docker environment at a glance.
Portainer provides several options for deploying new applications. One of these is stacks. In the Portainer interface, click on the Stacks menu item located on the left sidebar. Then, press the Add stack button at the top-right corner of the Stacks page.
Configure the Stack:
Name: Provide a name for your stack.
Compose File: You can either write your Docker Compose file in the provided editor or upload an existing file.
Environment Variables: Optionally, define any environment variables needed for your services.
Under Build method, choose Web editor. This lets you type out a Docker Compose file manually.
In the big text box, paste your entire docker-compose.yml
services:
db:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
volumes:
- db:/var/lib/mysql
wordpress:
image: wordpress:latest
ports:
- 8880:80
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=${MYSQL_USER}
- WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD}
- WORDPRESS_DB_NAME=${MYSQL_DATABASE}
volumes:
db:
The services section defines the different containers that will be created and run as part of your application.
A. db (MySQL Service):
image: mysql:8.0: This specifies the Docker image to use, which is MySQL version 8.0.
environment: This section sets environment variables needed for the MySQL database:
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}: Sets the root password for the MySQL database. The actual value is pulled from an environment variable.
MYSQL_DATABASE=${MYSQL_DATABASE}: Specifies the name of a database to create when the container starts.
MYSQL_USER=${MYSQL_USER}: Defines a user that will be created on the specified database.
MYSQL_PASSWORD=${MYSQL_PASSWORD}: Sets the password for the MySQL user defined above.
volumes: This mounts a named volume to persist MySQL data:
db:/var/lib/mysql: The db volume is used to store MySQL data files, ensuring data persistence even if the container is stopped or removed.
B. wordpress (WordPress Service)
image: wordpress:latest: This specifies the Docker image for WordPress, pulling the latest version.
ports: This option maps the container’s internal port to a port on the host machine:
- 8880:80: Maps port 80 in the container (where WordPress runs) to port 8880 on the host. You can access WordPress via http://localhost:8880
or http://192.168.1.40:8880
.
environment: This section sets environment variables for the WordPress container:
WORDPRESS_DB_HOST=db: Specifies the hostname of the database service (in this case, the MySQL service named db).
WORDPRESS_DB_USER=${MYSQL_USER}: Uses the same MySQL user defined earlier.
WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD}: Uses the same password defined for the MySQL user.
WORDPRESS_DB_NAME=${MYSQL_DATABASE}: Specifies the database name that WordPress will use.
volumes: This section defines named volumes that can be reused and shared among services.
db: Declares the db volume for persistent data storage for the MySQL service.
By using environment variables, the configuration allows for flexible and secure management of sensitive data like passwords and database names. This setup provides a basic yet fully functional WordPress site backed by a MySQL database.
Click Deploy the stack.
When using a Docker Compose file that includes environment variable substitution (like ${VARIABLE}), you need to provide values for these variables when you start your stack. To do this, scroll down the page until you reach the section for environment variables and click on the Add an environment variable button to create a new key-value pair. Repeat this process to add the following four required variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD.
This docker-compose.yml file orchestrates two services:
Finally, you can access the created WordPress site by opening your favorite browser and heading to http://192.168.1.40:8880
.