How to run 2 different commands from docker-compose command:


I want to run 2 different commands for my service from docker-compose.

  1. bash
  2. config /etc/config.yaml

Currently, my docker-compose looks like the below. I want the bash script to run after the config command


        build: .
            - 8080:8080
         - "USER=${USER}"
         - "PASSWORD=${PASSWORD}"
            - ./conf/config.yaml:/etc/api.yaml
        command: ["-config", "/etc/api.yaml"]


Write a new entrypoint script.


/bin/api "$@"

# perhaps
source /

# or exec
exec /

Copy this into your image on build.

COPY --chmod=755 /

This will result in the arguments you are passing in your compose file to be passed to /bin/api, and after that your script is executed.

I am not sure if that would be actually useful. The API command looks like it’s initiating a long-running process, so your script might never really run.

You could also dome something like this in your entrypoint.


  sleep 5
  source /

run_script &

exec /bin/api "$@"

It would hide errors from that script though, so its not really solid.

This would run the function in the background, which would sleep 5 seconds to give the API time to start, and then run the script while the API is running.

It’s hard to say, without knowing what your script is doing, what would be a good solution. The second suggestion feels definitely a bit hacky.

Answered By – The Fool

Answer Checked By – Jay B. (GoLangFix Admin)

Leave a Reply

Your email address will not be published.