简体   繁体   English

如果我要启动 docker-compose 的 docker(在我的情况下是 portainer),我该如何配置默认的管理员用户:密码与 docker?

[英]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 上设置了管理员密码!

  1. Create a script to generate your password:创建一个脚本来生成你的密码:
$ 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
  1. Give your permission:给予您的许可:
chmod u+x portainer-pass.sh
  1. generate your password:生成您的密码:
./portainer-pass.sh c7e694055489cb2051195a2be1740992

Output: $2y$05$bGljp9ThZkfNaZuKvDUB3uKpXecI5SDZ6s6Xga8azv4JQUDXmHV82输出: $2y$05$bGljp9ThZkfNaZuKvDUB3uKpXecI5SDZ6s6Xga8azv4JQUDXmHV82

  1. Put in "CMD" of the Dockerfile:放入 Dockerfile 的“CMD”:
# 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.

相关问题 如何将命令行选项发送到我的“docker-compose up”开始的dockerized程序? - How can I send command line options to my dockerized program that I start with “docker-compose up”? 我如何保证 docker 主机卷在多次 docker-compose up 和 docker-compose-down 之后有正确的权限 - how can i guarantee docker host volume have the right permission after multiple `docker-compose up` & `docker-compose-down` 如何将此运行 docker 命令转换为 docker-compose? - How can I translate this run docker command into docker-compose? 如何在加载 docker 容器而不运行 docker-compose 后运行它? - How do I run my docker container after loading it without running docker-compose up? 如何以与 docker-compose 相同的方式在远程服务器上运行 Docker 容器? - How can I run a Docker container on a remote server in the same manner as docker-compose up? 为什么我的docker镜像在使用docker run(image)时没有运行,但是docker-compose生成的容器却可以跑起来? - Why is my docker image not running when using docker run (image), but i can run containers generated by docker-compose up? 设置docker-machine主机后如何在本地使用docker-compose? - How can I use docker-compose locally after setting up a docker-machine host? 如果成功,如何构建 shell 脚本来构建 Docker-Compose Image 并启动 Docker 容器? - How can I build a shell script to build a Docker-Compose Image and start up the Docker container if successful? 我可以在没有网络的情况下设置 docker-compose 配置吗? - Can I set up a docker-compose configuration with no networks? Portainer:使用环境来自 docker-compose - Portainer: Use environment from docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM