Search This Blog

Saturday 10 April 2021

Build an Apache Instance using a Dockerfile

Step 1) Create a Dockerfile

 [root@stapp03 docker]# ls -rtl
total 12
drwxr-xr-x 2 root root 4096 Apr 11 02:53 html
drwxr-xr-x 2 root root 4096 Apr 11 02:53 certs
-rw-r--r-- 1 root root  518 Apr 11 02:53 Dockerfile

[root@stapp03 docker]# cat Dockerfile 
FROM httpd:2.4.43

RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf

RUN sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' conf/httpd.conf

RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' conf/httpd.conf

RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' conf/httpd.conf

COPY certs/server.crt /usr/local/apache2/conf/server.crt

COPY certs/server.key /usr/local/apache2/conf/server.key

COPY html/index.html /usr/local/apache2/htdocs/


Step 2) Build the docker file.

[root@stapp03 docker]# docker build . 
Sending build context to Docker daemon  9.216kB
Step 1/8 : FROM httpd:2.4.43
2.4.43: Pulling from library/httpd
bf5952930446: Pull complete 
3d3fecf6569b: Pull complete 
b5fc3125d912: Pull complete 
3c61041685c0: Pull complete 
34b7e9053f76: Pull complete 
Digest: sha256:cd88fee4eab37f0d8cd04b06ef97285ca981c27b4d685f0321e65c5d4fd49357
Status: Downloaded newer image for httpd:2.4.43
 ---> f1455599cc2e
Step 2/8 : RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf
 ---> Running in 8a15fb135929
Removing intermediate container 8a15fb135929
 ---> 68a60d63d706
Step 3/8 : RUN sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' conf/httpd.conf
 ---> Running in 4428dc0a8f75
Removing intermediate container 4428dc0a8f75
 ---> 120807ee4b24
Step 4/8 : RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' conf/httpd.conf
 ---> Running in 16a20cd89c06
Removing intermediate container 16a20cd89c06
 ---> adccf5d023cc
Step 5/8 : RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' conf/httpd.conf
 ---> Running in 20517b5c3139
Removing intermediate container 20517b5c3139
 ---> eb9a29e245f6
Step 6/8 : COPY certs/server.crt /usr/local/apache2/conf/server.crt
 ---> 778c38d0b9e8
Step 7/8 : COPY certs/server.key /usr/local/apache2/conf/server.key
 ---> a296ecb733bf
Step 8/8 : COPY html/index.html /usr/local/apache2/htdocs/
 ---> f8770710ddf9
Successfully built f8770710ddf9

Step 3) Verify if the image is running. 

[root@stapp03 docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              f8770710ddf9        6 seconds ago       166MB
httpd               2.4.43              f1455599cc2e        8 months ago        166MB

No comments: