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/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
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

#!/bin/bash
/usr/sbin/init
...
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?

Thanks


(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 .
Thanks

or you cam email me on shrenikchhajed1@gmail.com