Reputation: 91
I am trying to create a docker-compose which sets up a huge environment of dockers with portainer as a manager.
The problem is that the first time the user use "docker-compose up" and the portainer start running, he has to navigate to portainer web interface (localhost:9000) and set-up the admin user and password.
How can I automate this step and create a portainer with a default user that I define so when the user navigate to portainer on the first time, the admin user is already created.
Here is my docker-compose.yml
version: '3.3'
services:
portainer:
image: portainer/portainer
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer/portainer_data:/data
ports:
- "9000:9000"
Upvotes: 7
Views: 16313
Reputation: 56
I set the admin password directly on Dockerfile!
$ cat <<EOF > portainer-pass.sh
#!/usr/bin/env bash
if [ -z "\$1" ]; then
echo -e "\\nPlease call '\$0 <password>' to run this command!\\n"
exit 1
fi
htpasswd -nb -B admin \$1 | cut -d ":" -f 2
EOF
chmod u+x portainer-pass.sh
./portainer-pass.sh c7e694055489cb2051195a2be1740992
Output: $2y$05$bGljp9ThZkfNaZuKvDUB3uKpXecI5SDZ6s6Xga8azv4JQUDXmHV82
# Set fixed portainer image
FROM portainer/portainer-ce:latest
# Set default admin password at startup
CMD ["--admin-password", "$2y$05$bGljp9ThZkfNaZuKvDUB3uKpXecI5SDZ6s6Xga8azv4JQUDXmHV82"]
# Default portainer web port
EXPOSE 9443
Here you NOT need to be replace $
to $$
!
Upvotes: 0
Reputation: 124
Following Mohsen's remark, you must run docker-compose down
, each time you need to restart and initialise a new admin password, with the option -v
if you want also to delete the volumes.
https://github.com/portainer/portainer/issues/1506#issuecomment-352273682
Using version: '3.3'
in the docker-compose.yml file is mandatory in this later case.
Upvotes: 0
Reputation: 888
You need to escape each $
character inside the hashed password with another $
:
$2y$05$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
To
$$2y$$05$$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
Upvotes: 2
Reputation: 2444
You can set admin password ONLY for the first run of the container. Use this repository:
Upvotes: 1
Reputation: 2613
Portainer allows you to specify an encrypted password from the command line for the admin account. You need to generate the hash value for password.
For example, this is the hash value of password - $$2y$$05$$arC5e4UbRPxfR68jaFnAAe1aL7C1U03pqfyQh49/9lB9lqFxLfBqS
In your docker-compose file make following modification
version: '3.3'
services:
portainer:
image: portainer/portainer
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer/portainer_data:/data
command: --admin-password "$$2y$$05$$arC5e4UbRPxfR68jaFnAAe1aL7C1U03pqfyQh49/9lB9lqFxLfBqS"
ports:
- "9000:9000"
--admin-password This flag is used to specify an encrypted password in Portainer.
More information can be found in documentation - Portainer
Hope this will help you.
Upvotes: 8