Docker Community Forums

Share and learn in the Docker community.

Startup script after init in centos 7

(Clouderafn) #1

I create a Dockerfile that build image based on centos7. In order to get systemd working, following doc is applied

Dockerfile looks like content below

FROM centos:centos7

ENV container docker

RUN (cd /lib/systemd/system/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/*; \
rm -f /lib/systemd/system/*udev*; \
rm -f /lib/systemd/system/*initctl*; \
rm -f /lib/systemd/system/*;\
rm -f /lib/systemd/system/*;
VOLUME [ "/sys/fs/cgroup" ]
ADD startup-script /startup-script
RUN chmod +x /startup-script
CMD ["/usr/sbin/init"]

With this, docker build -t docker-image works fine. However where to place the startup script after /usr/sbin/init?

CMD ["/usr/sbin/init", “/startup-script”] won’t execute /startup-script. Changing CMD to[…] ENTRYPOINT ["/startup-script"] with /startup-script containing

commands or operations (which are not something like (re)start service but some pre- post- operations) to be executed 
exec "#@"

doesn’t work either.

How can I execute custom startup script after executing /usr/sbin/init in docker?


(Schhajed) #2

@clouderafn did you find out a way to do that ? I am a newbie and stuck with same issue
Would be great help if you could share as to what you did .

or you cam email me on