I want to run a script after a docker image has been initialized. The image in question is a node:16 with python and other stuff
https://github.com/Flagsmith/flagsmith/blob/main/Dockerfile
Anyway, if I run the image without commands or entry-point it does start successfully. If I login using docker exec -it ###### /bin/bas
I can then run either sh
, bash
or even python
However having:
flagsmith:
image: flagsmith/flagsmith:latest
environment:
# skipping for readibility
ports:
- "9000:8000"
depends_on:
- flotto-postgres
links:
- flotto-postgres
volumes: ['./init_flagsmith.py:/init_flagsmith.py', './init_flagsmith.sh:/init_flagsmith.sh']
command: /bin/bash '/init_flagsmith.sh' # <-------- THIS GUY IS NOT WORKING
it does not run, and the returned error is 0 with this message (depending on the tool I run on init_flagsmith.sh
:
ERROR: unrecognised command '/bin/bash'
If you look at the end of the Dockerfile you link to, it specifies
In the Compose file, the
command:
overrides the DockerfileCMD
, but it still is passed as arguments to theENTRYPOINT
. Looking at therun-docker.sh
script, it does not accept a normal shell command as its arguments, but rather one of a specific set of command keywords (migrate
,serve
, ...).You could in principle work around this by replacing
command:
withentrypoint:
in your Compose file. However, you'll still run into the problem that a container only runs one process, and so your setup script runs instead of the normal container process.What you might do instead is set up your initialization script to run the main entrypoint script when it finishes.
I also might package this up into an image, rather than injecting the files using
volumes:
. You can create an imageFROM
any base image you want to extend it.Then you can remove these options from the Compose setup (along with the obsolete
links:
)