I need some advice on the following topic. I am trying to build a docker image for a Percona mysql server with a pmm client installed in the container alongside with the database. I have made a Dockerfile for this installation which is running fine.
My problem is that on the first container run I need to set up a configuration for the pmm client. Currently I do this manually, but I plan to run the container in a Openshift environment. Hence I need to automated the initial configuration.
The configuration commands which I have to execute requires the pmm server (another docker container) to already be available. I have red about the wait-for-it.sh script which I can use to poll the availability of the pmm-server. So far so good. Now my problem is that once the server is up, I need to execute the configuration commands for the pmm client with root priviledges, but I do not want to let the container run with root priviledges once the setup is finished.
Hence from the logic:
- start container
- wait-for-it.sh till pmm-server is up and running
- pmm-client configuration on first container startup with root priviledges
- switch to non root for standard execution
-Currently I have not found a solution on how I can temporarily switch to root to configure pmm client and afterwords switch to default user.
- Also I would be interested if I have to implement logic in the startup script myself to check if the container is started the first time and save the state for subsequent runs, or if docker-compose delivers a better solution to this already.
Thanks for your help.