Deploying Portainer behind nginx reverse proxy
Deploying in a Docker Standalone scenario
To deploy Portainer behind an nginx proxy in a Docker standalone scenario you must use a Docker Compose file. In the following docker-compose.yml you will find the configuration of the nginx proxy and the Portainer Server.
version: "2"
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
restart: always
ports:
- "80:80"
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
portainer:
image: portainer/portainer-ee:lts
command: -H unix:///var/run/docker.sock
restart: always
environment:
- VIRTUAL_HOST=portainer.yourdomain.com
- VIRTUAL_PORT=9000
ports:
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
volumes:
portainer_data:To start working with this recipe, change the VIRTUAL_HOST value then deploy Portainer by running the following:
When this has finished, run docker ps . You should see an output similar to this:
Once the deployment has finished you can browse portainer.yourdomain.com.
Deploying in a Docker Swarm scenario
Deploying Portainer in Docker Swarm behind nginx has similar steps to the Docker Standalone scenario. Before deploying, you need to create two elements: networks and volumes.
This deployment assumes you are running one manager node. If you are using multiple managers we advise reading this article before proceeding.
First, create two networks:
One for the agent and the communication with the Portainer Server.
One to 'expose' the Portainer container to the same network as the reverse proxy.
Next, create the volume:
And finally, save the following recipe as portainer.yml:
To start working with this recipe, change the VIRTUAL_HOST value then deploy Portainer by running the following:
To check the deployment, run docker service ls. You should see an output similar to the following:
Once the services are running, you will be able to access Portainer from the URL you defined earlier, for example: portainer.yourdomain.com.
Last updated
Was this helpful?