Fred Bongers
Fred Bongers

Reputation: 267

Start service automatic inside Docker container

I'm trying to start a service like Apache2 automatic inside a Docker container

My Dockerfile:
FROM ubuntu:14.04

RUN apt-get update
RUN apt-get -y install apache2
ADD ./startup.sh /opt/startup.sh
RUN chmod +x /opt/startup.sh
CMD ["/bin/bash", "/opt/startup.sh"]
RUN /opt/startup.sh

My startup.sh:
#!/bin/bash
service apache2 start

But Apache2 isn't started automatic in the container.

Upvotes: 2

Views: 4871

Answers (1)

lloydpick
lloydpick

Reputation: 1649

Containers by themselves have no capability to start services in the traditional sense that you're used to, eg. by using upstart or systemd. So you just have to start apache manually...

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y install apache2

EXPOSE 80 443
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

Remember that when you start the container you will need to map the port correctly with the -p parameter. The dockerfile doesn't deal with any VOLUMES, this simply installs apache2 and starts it. If you need to understand how those work, you'll need to consult the Dockerfile Reference.

Upvotes: 4

Related Questions