dockerfile

通过dockerfile创建⼀个在启动容器时,就可以启动httpd服务的镜像
步骤
1. 创建⼀个⽬录,⽤于存储Docker file所使⽤的⽂件
1. 在此⽬录中创建Docker file⽂件,以及镜像制作所使⽤的⽂

1. 使⽤docker build创建镜像
1. 使⽤创建的镜像启动容器(验证)
思考
1. 基础镜像
1. yum -y install httpd
1. 使⽤脚本启动服务(httpd -k start)
1. 应该将httpd服务放在前端执⾏
1. 暴露端⼝ 80/tcp
1. 添加⼀个测试⽂件,⽤于验证软件是否可⽤
过程
# 1.创建⽬录
[root@docker001 ~]# mkdir test
# 2.跳转到⽬录中[root@docker001 ~]# cd test/
# 3.编辑启动脚本
[root@docker001 test]# vim start.sh
[root@docker001 test]# cat start.sh
######################################
#!/bin/bah
rm -rf /run/httpd/*
exec /sbin/httpd -D FOREGROUND
######################################
# 4.编辑index.html⽂件
[root@docker001 test]# vim index.html
# 5.编辑Dockerfile
[root@docker001 test]# vim Dockerfile
####################################
FROM centos_yum:v0
MAINTAINER "httpd server start
15773141955@163.com"
RUN yum clean all
RUN yum makecacheRUN 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"]
####################################
# 6.创建镜像
[root@docker001 test]# docker build -t
centos:httpd .
[+] Building 51.6s (12/12) FINISHED
docker:default=> [internal] load build definition from
Dockerfile
0.0s
=> => transferring dockerfile: 309B
0.0s
=> [internal] load metadata for
docker.io/library/centos_yum:v0
0.0s
=> [internal] load .dockerignore
0.0s
=> => transferring context: 2B
0.0s
=> [1/8] FROM docker.io/library/centos_yum:v0
0.0s
=> [internal] load build context
0.0s
=> => transferring context: 180B
0.0s
=> [2/8] RUN YUM clean all
2.3s
=> [3/8] RUN YUM makecache
42.7s
=> [4/8] RUN YUM -y install httpd
5.8s
=> [5/8] ADD START.SH /START.SH
0.0s=> [6/8] RUN CHMOD -v +x /start.sh
0.2s
=> [7/8] ADD INDEX.HTML /VAR/WWW/HTML/
0.0s
=> exporting to image
0.5s
=> => exporting layers
0.4s
=> => writing image
sha256:a488bc9f4cfb58a91baa57c2ab9faf615d457ff8714
e4e958e7220a253469ed 0.0s
=> => naming to docker.io/library/centos:httpd
# 7.查看镜像
[root@docker001 test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED
SIZE
centos httpd a488bc9f4cfb About a
minute ago 352MB
centos nginx 12fea1b890de 41 hours ago
366MB
centos java17 b6bf774de7bb 41 hours ago
550MB
centos_yum v0 191d9c84f461 2 days ago
260MBmysql latest a82a8f162e18 4 weeks ago
586MB
# 9.创建容器测试
[root@docker001 test]# docker run -d --name c0
centos:httpd
c245d9f9f3e0d6526d80e117ebd7b4c2870a1e12558192f1da
1e681cabdc4e87
[root@docker001 test]# docker ps --all
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
c245d9f9f3e0 centos:httpd "/bin/bash
/start.sh" 21 seconds ago Up 20 seconds
80/tcp c0
# 10.查看ip地址
[root@docker001 test]# docker inspect c0
# 访问测试
[root@docker001 test]# curl 172.17.0.2
p
pp
ppp
pppp
ppppppppppp
ppppppp
pppppppp
测试挂载其他项⽬
[root@docker001 test]# docker run -d -v
/opt:/var/www/html --name c1 centos:httpd
3c97af2d11a56b9c2f2ea4eb6bb0a7ff18d6f26d0f777f68a4
eb4a20b9c61835
[root@docker001 test]# eche
"adsfadfafwqrdfqdsafdgdfsgda" > /opt/index.html
-bash: eche: 未找到命令
[root@docker001 test]# echo
"adsfadfafwqrdfqdsafdgdfsgda" > /opt/index.html
[root@docker001 test]# curl 172.17.0.3
adsfadfafwqrdfqdsafdgdfsgda
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
948f20e1ed4758e78759de8f9ce9b34

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值