Starting a service inside a Docker file

I create a Docker container, and in this container I load the Apache service. Is it possible at some point to automatically start the Apache service? Systemctl start httpd does not work inside the Docker file.

Basically, I want the apache service to start when the docker container starts.

FROM centos:7
MAINTAINER me <me@me.com>
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"]
+4
source share
2 answers

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

You can also run:

docker run -d <image name> /usr/sbin/httpd -DFOREGROUND
+2
source

Docker ( ), ENTRYPOINT, , - "" . CMD , , , /:

docker exec ENTRYPOINT , CMD. , .. docker -d -d .

ENTRYPOINT, . / --entrypoint.

:

exec ENTRYPOINT , CMD , .

, ENTRYPOINT /, CMD .

ENTRYPOINT, CMD, "" ( ) "" . :

FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]

, :

ENTRYPOINT ["/usr/sbin/httpd"] 
CMD ["-DFOREGROUND"]

:

docker run -d <image name>

- ,

docker run -d <image name> -DBACKGROUND

, -DBACKGROUND, -DFOREGROUND.

+2

All Articles