I have a docker image that spawns container with /usr/sbin/init
as the pid 1
and ppid 0
, I need to execute a script that does some changes once at runtime. and then let the container start as it start right now, i.e. /usr/sbin/init
as pid 1
and ppid 0
.
I tried this but it executes the script and then the container exits. What can I do? Any help is appreciated.
I would suggest writing/adding a custom entrypoint. If your container does not make use of entrypoint yet, this is straightforward, just have a /entrypoint.sh
that is something like
#!/bin/bash
your commands
exec $@
if your image already makes use of entrypoint, you need to either merge with that EP or call it in yours according to it's requirements. You will also need to add
ENTRYPOINT /entrypoint.sh
to your Dockerfile.
Side note: if your initiation can be completely separated from the runtime container, then you might want to use init-container instead.