通过dockerfile创建⼀个在启动容器时,就可以启动httpd服务的镜像
[root@docker001 ~]# mkdir test
[root@docker001 ~]# cd test/
[root@docker001 test]# vim start.sh
#!/bin/bah
rm -rf /run/httpd/*
exec /sbin/httpd -D FOREGROUND
[root@docker001 test]# vim index.html
[root@docker001 test]# vim Dockerfile
FROM centos_yum:v0
MAINTAINER "httpd server start
15773141955@163.com"
RUN yum clean all
RUN yum makecache
RUN yum -y install httpd
ADD start.sh /start.sh
RUN chmod -v +x /start.sh
Add index.html /var/www/html/
EXPOSE 80
WORKDIR /
CMD ["/bin/bash","/start.sh"]
[root@docker001 test]# docker build -t centos:httpd .
[root@docker001 test]# docker run -d --name c0 centos:httpd
[root@docker001 test]# docker ps --all
[root@docker001 test]# docker inspect c0
[root@docker001 test]# curl 172.17.0.2
测试挂载其他项⽬
[root@docker001 test]# docker run -d -v /opt:/var/www/html --name c1 centos:httpd
[root@docker001 test]# echo "adsfadfafwqrdfqdsafdgdfsgda" > /opt/index.html
[root@docker001 test]# curl 172.17.0.3
yum -y install yum-plugin-ovl
配置nginx应⽤镜像
FROM centos:latest
MAINTAINER "NGINX"
RUN rm -rf /etc/yum.repos.d/*
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-vault-
8.5.2111.repo
RUN yum clean all && yum makecache
RUN yum -y install epel-release && yum -y
install nginx
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
WORKDIR /
CMD /usr/sbin/nginx
[root@docker001 ~]# docker run -d --name c1 -p80:80 -v /opt/:/usr/share/nginx/html/ centos:nginx