Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a service inside of a Dockerfile

Tags:

I'm building a Docker container and in this container I am downloading the Apache service. Is it possible to automatically start the Apache service at some point? Systemctl start httpd does not work inside of the Dockerfile.

Basically, I want the apache service to be started when the docker container is started.

FROM centos:7
MAINTAINER me <[email protected]>
RUN yum update -y && yum install -y httpd php
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" ]
EXPOSE 80
EXPOSE 443
CMD ["/usr/sbin/init"]
like image 370
J. Doe Avatar asked Apr 19 '16 21:04

J. Doe


1 Answers

Try using CMD ["/usr/sbin/httpd", "-DFOREGROUND"].

You also can run :

docker run -d <image name> /usr/sbin/httpd -DFOREGROUND
like image 165
vmonteco Avatar answered Sep 28 '22 02:09

vmonteco