Build the apache container

1. Create a file

mkdir /opt/apache
cd /opt/apache/

Insert picture description here

2. Write a Dockerfile

vim Dockerfile

#基础镜像
FROM centos:7
#维护镜像人员信息
MAINTAINER Ruyi
#镜像操作指令安装软件
RUN yum -y update
RUN yum -y install httpd
#开启80端口
EXPOSE 80
#复制网站首页信息
ADD index.html /var/www/html/index.html
#将执行脚本复制到镜像中
ADD run.sh /run.sh
RUN chmod 755 /run.sh
#启动容器时执行脚本
CMD ["/run.sh"]

Insert picture description here

3. Write the startup file

vim run.sh

#!/bin/bash
rm -rf /run/htttpd/*
exec /usr/sbin/apachectl -D FOREGROUND

Insert picture description here

4. Write the homepage file of the webpage

echo "ruyi" >> index.html

Insert picture description here

5. Establish a mirror

docker build -t httpd:centos .

Insert picture description here

6, the designated port to establish a container

docker run -d -p 1234:80 httpd:centos 

Insert picture description here

7. Log in to the designated port to view the interface

http://192.168.199.40:1234/

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51614581/article/details/115176219