Automate user creation to use with Docker

I have one question: I created small Docker script to build the image with Grav. Everything works fine except I cant add admin user automatically, as part of the build procedure. I have tried to use cat and echo to automate usage of admin plugin, but resulting file is not OK so I am prevented to login.

Am I missing something or I shall create user file directly (in which case I am not sure how to properly generate password hash)?

Thank you kindly

Hi @nikoladsp, I don’t know anything about Docker, but it might help you to know that you can define a default unhashed password in a user.yaml file and after that first login it will be properly hashed.

So, for example if in your created user.yaml file you have this:
password: <yourpasswordhere>

After first login it will change to this:
hashed_password: <hashedpasswordhere>

I hope the above might be of help.

Thanks - I did not know this; I might use it and immediately call login using the curl. Is there any sample on how to login using curl?

Best regards

1 Like

I do not know of one, might be worth a shot to ask in the Grav Discord room?

you can create a user file (with hashed or cleartext password, as Paul already mentioned) before and then just copy that into the docker container (use ‘docker cp’ command for that).
Or, even easier, mount the whole webroot folder locally, then everything in there will be synchronized from/to container.
as an example, just look at the docker-compose.yml file at my GitHub Docker Project

1 Like

Thank you all for the answers. I created entry for user in Dockerfile with cleartext password and it works!

Best regards

1 Like