dwitz
dwitz

Reputation: 1230

Docker CentOS image does not auto start httpd

I'm trying to run a simple Docker image with Apache and a PHP program. It works fine if I run

docker run -t -i -p 80:80 my/httpd /bin/bash

then manually start Apache

service httpd start

however I cant get httpd to start automatically when running

docker run -d -p 80:80 my/httpd

Apache will startup then container exists. I have tried a bunch of different CMDs in my docker file

CMD /etc/init.d/httpd start
CMD ["service" "httpd" "start"]
CMD ["/bin/bash", "/etc/init.d/httpd start"]
ENTRYPOINT /etc/init.d/httpd CMD start
CMD ./start.sh

start.sh is

#!/bin/bash
/etc/init.d/httpd start

However every-time docker instance will exist after apache starts

Am I missing something really obvious?

Upvotes: 28

Views: 58004

Answers (6)

Ashish S Bhavsar
Ashish S Bhavsar

Reputation: 1

FROM docker.io/centos:7
RUN yum update -y
RUN yum install httpd -y
CMD httpdctl -D  FOREGROUND

Upvotes: 0

Trong Nguyen
Trong Nguyen

Reputation: 109

In the end of Dockerfile, insert below command to start httpd

# Start httpd 
ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]

Upvotes: 0

Dasimsetty Giridhar
Dasimsetty Giridhar

Reputation: 1

This works for me

ENTRYPOINT /usr/sbin/httpd -D start && /bin/bash

Upvotes: -1

Jiri
Jiri

Reputation: 16625

You need to run apache (httpd) directly - you should not use init.d script.

Two options:

  1. you have to run apache in foreground: /usr/sbin/apache2 -DFOREGROUND ... (or /usr/sbin/httpd in CentOS)
  2. you have to start all services (including apache configured as auto-run) by executing /sbin/init as entrypoint.

Upvotes: 25

MalyaBee
MalyaBee

Reputation: 1

Simple Dockerfile to run httpd on centOS

FROM centos:latest
RUN yum update -y
RUN yum install httpd -y
ENTRYPOINT ["/usr/sbin/httpd","-D","FOREGROUND"]

Commands for building images and running container

Build

docker build . -t chttpd:latest

Running container using new image

docker container run  -d -p 8000:80 chttpd:latest

Upvotes: 0

Hemerson Varela
Hemerson Varela

Reputation: 25792

Add this line in the bottom of your Dockerfile to run Apache in the foreground on CentOS

ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]

Upvotes: 19

Related Questions