[英]how can I configure the default admin user:password with docker if i am launching docker-compose up of a docker(portainer in my case)?
I am trying to create a docker-compose which sets up a huge environment of dockers with portainer as a manager.我正在尝试创建一个 docker-compose,它设置了一个巨大的 docker 环境,以 portainer 作为经理。
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.问题是当用户第一次使用“docker-compose up”并且 portainer 开始运行时,他必须导航到 portainer web 界面(localhost:9000)并设置管理员用户和密码。
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.如何自动执行此步骤并使用我定义的默认用户创建 portainer,以便当用户第一次导航到 portainer 时,已经创建了 admin 用户。
Here is my docker-compose.yml这是我的 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"
Portainer allows you to specify an encrypted password from the command line for the admin account. Portainer 允许您从命令行为管理员帐户指定加密密码。 You need to generate the hash value for password.
您需要为密码生成哈希值。
For example, this is the hash value of password - $$2y$$05$$arC5e4UbRPxfR68jaFnAAe1aL7C1U03pqfyQh49/9lB9lqFxLfBqS例如,这是密码的哈希值 - $$2y$$05$$arC5e4UbRPxfR68jaFnAAe1aL7C1U03pqfyQh49/9lB9lqFxLfBqS
In your docker-compose file make following modification在您的 docker-compose 文件中进行以下修改
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. --admin-password此标志用于指定 Portainer 中的加密密码。
More information can be found in documentation - Portainer更多信息可以在文档中找到 - Portainer
Hope this will help you.希望这会帮助你。
You need to escape each $
character inside the hashed password with another $
:您需要使用另一个
$
对散列密码中的每个$
字符进行转义:
$2y$05$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
To到
$$2y$$05$$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
You can set admin password ONLY for the first run of the container.您只能为容器的第一次运行设置管理员密码。 Use this repository :
使用此存储库:
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.按照 Mohsen 的说法,您必须运行
docker-compose down
,每次需要重新启动并初始化新的管理员密码时,如果您还想删除卷,请使用选项-v
。
https://github.com/portainer/portainer/issues/1506#issuecomment-352273682 https://github.com/portiner/portiner/issues/1506#issuecomment-352273682
Using version: '3.3'
in the docker-compose.yml file is mandatory in this later case.在后面的情况下,docker-compose.yml 文件中的使用
version: '3.3'
是强制性的。
I set the admin password directly on Dockerfile!我直接在 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
输出:
$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 $$
!在这里,您不需要将
$
替换为$$
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.