0

As far as I know, it's a good practice to use containers from Dockerhub instead of making my own ones. Most of those contain docker-entrypoint.sh script that is executed on startup. However, sometimes I need to do something on startup in addition to what is already described in docker-entrypoint.sh. Namely, I'm setting up a RabbitMQ container, I want to use a bind mount to save configs, but the config directory has to be owned by rabbitmq user. I wish I could execute chown -R rabbitmq /etc/rabbitmq on startup in addition to docker-entrypoint.sh, but I don't know how to do that.

I understand that I can simply clone the repo with Dockerfile and entrypoint from git, add something to the entrypoint and build docker image manually, but it looks like a crutch. I can also just attach to the container and execute that command manually which also looks like a crutch.

  • Or fix the issue on github by creating a pull request – 030 Apr 25 '18 at 17:57
1

Simply write a Dockerfile which uses that image as a base. Then you can replace individual files (like the entrypoint) easily.

Also, instead of replacing, you could rename the original entry script, create your own, which does whatever it needs to do, and then just calls the original.

Somewhat like this:

  • Dockerfile:

    FROM fancy-base-image:1.2.3
    RUN mv docker-entrypoint.sh docker-entrypoint-original.sh
    ADD docker-entrypoint.sh
    
  • docker-entrypoint.sh:

    #!/bin/bash
    echo Do something.
    ./docker-entrypoint-original.sh
    echo Do something else
    

Obviously this is just a fake example, you'll have to adjust for directory and file names and such.

0

One could fix the issue by creating a pull request

Or one could find another github project that has less or no issues

Or one could adjust or create an own image

I wish I could execute chown -R rabbitmq /etc/rabbitmq on startup in addition to docker-entrypoint.sh, but I don't know how to do that

Once the docker container runs (one could verify this by issuing docker ps), one could run docker exec -it container /bin/bash and run commands. Note: I personally prefer to investigate why the owner and group is not set to rabbitmq instead of fixing it in a running container as it is mutable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.