Docker Community Forums

Share and learn in the Docker community.

Howto start init script with runtime dependencies via docker-compose

Hello together,
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 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
  • 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.
Best regards,

You migh want to take a look at the supervisor s6-overlay. You can add start/stop scripts that take care of the preparation and one or more services that need to be started. Even though the container starts as the root user, you can execute your services with a restricted uid:gid.

The common approach is to either render the configuration file on every container start or to implement a check in your entrypoint scripts that perform actions depending on the existance of specific files/folders/result of commands.