Thursday, June 25, 2020

Start service using systemctl inside docker container

To run a container with systemctl services also running you need to run the docker container with /sbin/init as run command.

docker run -it -p 8080:80 -p 16700:16700 -d --privileged=true tagname /sbin/init


Also, while creating image, use below same options.


FROM centos:7
COPY a.rpm a.rpm
COPY b.rpm b.rpm
EXPOSE 80
EXPOSE 16700
RUN yum -y install a.rpm b.rpm
CMD ["/sbin/init"]

docker build -t tagname .

Reference

No comments:

Post a Comment