Answers: <p>Simply write a <code>Dockerfile</code> which uses that image as a base. Then you can replace individual files (like the entrypoint) easily.</p>
  
  <p>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.</p>
  
  <p>Somewhat like this:</p>
  
  <ul>
  <li><p>Dockerfile:</p>
  
  <pre><code>FROM fancy-base-image:1.2.3
  RUN mv docker-entrypoint.sh docker-entrypoint-original.sh
  ADD docker-entrypoint.sh
  </code></pre></li>
  <li><p>docker-entrypoint.sh:</p>
  
  <pre><code>#!/bin/bash
  echo Do something.
  ./docker-entrypoint-original.sh
  echo Do something else
  </code></pre></li>
  </ul>
  
  <p>Obviously this is just a fake example, you'll have to adjust for directory and file names and such.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-04-25T22:44:12.823Z
Answers: 2018-04-25T22:44:12.823Z
Answers: AnoE
Answers: <p>One could fix the issue by creating a pull request</p>
  
  <p>Or one could find another github project that has less or no issues</p>
  
  <p>Or one could adjust or create an own image</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Once the docker container runs (one could verify this by issuing <code>docker ps</code>), one could run <code>docker exec -it container /bin/bash</code> 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.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-04-25T18:01:00.237Z
Answers: 2018-04-25T19:51:19.327Z
Answers: 2018-04-25T19:51:19.327Z
Answers: 030
Body: <p>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 <code>docker-entrypoint.sh</code> script that is executed on startup. However, sometimes I need to do something on startup in addition to what is already described in <code>docker-entrypoint.sh</code>. 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 <code>rabbitmq</code> user. I wish I could execute <code>chown -R rabbitmq /etc/rabbitmq</code> on startup in addition to <code>docker-entrypoint.sh</code>, but I don't know how to do that.</p>
  
  <p>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.</p>
  
Comments: CC BY-SA 3.0
Comments: 2018-04-25T17:57:13.977Z
Comments: Or fix the issue on github by creating a pull request
Comments: 030
Tags: <docker>
Title: Running additional commands on Docker image startup
UserDisplayName: Artem Shalagin
ThreadText: # Running additional commands on Docker image startup
  
  (Asked by: username_0 on 2018-04-25)
  
  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.
  
  **Tags:** docker
  
  > **Comments:**
  > **username_1**: Or fix the issue on github by creating a pull request  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-04-25. Score: 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.
  
  
  ---
  
  ### Answer by username_1 on 2018-04-25. Score: 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.
  
  
  ---
  
  