This file aims to explain how to deploy Portainer inside a compose file with the admin password already set.
For this example, we'll use the password superpassword
.
Use the following command to generate a hash for the password:
docker run --rm httpd:2.4-alpine htpasswd -nbB admin 'superpassword' | cut -d ":" -f 2
The output of that command is the hashed password, it should be something similar to $2y$05$w5wsvlEDXxPjh2GGfkoe9.At0zj8r7DeafAkXXeubs0JnmxLjyw/a
.
If you try to use the hashed password in this form directly in your Compose file, the following error will be raised:
ERROR: Invalid interpolation format for "command" option in service "portainer": "--admin-password '$2y$05$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G'"
You need to escape each $
character inside the hashed password with another $
:
$$2y$$05$$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
Example of valid Compose file:
version: '2'
services:
portainer:
image: portainer/portainer:latest
ports:
- "9000:9000"
command: --admin-password '$$2y$$05$$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G'
networks:
- local
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer-data:/data
networks:
local:
driver: bridge
volumes:
portainer-data:
Output of docker-compose up
:
docker-compose up !10023
Creating network "porcomp_local" with driver "bridge"
Creating volume "porcomp_portainer-data" with default driver
Creating porcomp_portainer_1 ...
Creating porcomp_portainer_1 ... done
Attaching to porcomp_portainer_1
portainer_1 | 2018/03/08 01:18:37 Creating admin user with password hash $2y$05$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
portainer_1 | 2018/03/08 01:18:37 Starting Portainer 1.16.3 on :9000
Now you can login to the Portainer instance using the credentials admin
/ superpassword
.
I use this and it works fine:
docker run --rm httpd:2.4-alpine htpasswd -nbB admin YourPassword | cut -d ":" -f 2 | sed 's/\$/\$\$/g'
Thank you for sharing the information!