Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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"
like image 994
acochavosdi Avatar asked Jan 03 '23 04:01

acochavosdi


2 Answers

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.

like image 127
Rohan J Mohite Avatar answered Jan 05 '23 17:01

Rohan J Mohite


You need to escape each $ character inside the hashed password with another $:

$2y$05$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G

To

$$2y$$05$$ZBq/6oanDzs3iwkhQCxF2uKoJsGXA0SI4jdu1PkFrnsKfpCH5Ae4G
like image 25
Kerem Avatar answered Jan 05 '23 17:01

Kerem