Build a docker container with Apache

To create a docker container with Apache, create a Dockerfile

mkdir my-app
cd my-app
vi Dockerfile

Paste following content into the Dockerfile

from ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y apache2

RUN echo 'Hello World!' > /var/www/html/index.html

RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
 echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
 echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \ 
 echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \ 
 chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh

Now build an image with command

docker build -t sevrerok/okapache:1.0 .

Once image is build, you can see it using docker images command

[root@instance-20210426-0136 my-app]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sevrerok/okapache   1.2                 c3832b03b548        8 minutes ago       214MB
sevrerok/okapache   1.1                 d1a86f0eb69a        37 minutes ago      214MB
ubuntu              20.04               7e0aa2d69a15        2 days ago          72.7MB
sevrerok/okapache   1.0                 7e0aa2d69a15        2 days ago          72.7MB
[root@instance-20210426-0136 my-app]# 

To start a container with the image, run

docker container run -d -p 80:80 sevrerok/okapache:1.0

See docker build

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *