Atish Kumbhar
Atish Kumbhar

Reputation: 635

How to create a Docker image of centos provisioned with apache?

I have to create a centos base Docker image and I need to install apache within it. I have created a docker file with the below content:

FROM centos:7
Run yum update && yum install httpd httpd-tools -y

Need to do: When I run the container, it should be pointed to the browser like, localhost:8090. Can I get the steps to do the same?

Can anybody help, please?

Upvotes: 2

Views: 13803

Answers (1)

Dockstar
Dockstar

Reputation: 1028

First thing we need to adjust a few things in the Dockerfile:

FROM    centos:7
RUN yum update -y && yum install httpd httpd-tools -y

EXPOSE  80

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

The Expose Directive will tell the Docker engine that 80 should be available for publishing to the host. Since services don't run in containers, just applications, we will manually launch httpd in the foreground (/usr/sbin/httpd -D FOREGROUND).

Then in the same directoy as the docker file, issue the docker build

docker build -t "centosapache:0.1" .

Your docker run command would look like

docker run -d -p 8090:80 -v /home/user/web:/var/www/html centosapache:0.1

-d initializes it in detached or daemon mode -p maps port 8090 on the host to port 80 of the container -v will map directory /home/user/web of your host to /var/www/html of the container (optional, but great for PHP)

Then we just specify the image and version to run. Since the docker file had a default CMD of starting apache, you don't need to override it.

Upvotes: 9

Related Questions