Running additional commands on Docker image startup 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.
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.