Dockerfile构建镜像
1.先创建一个文件夹
[root@localhost ~]# mkdir test
[root@localhost ~]# cd test
2.创建Dockerfile
[root@localhost test]# vim Dockerfile
3.用docker build创建镜像
[root@localhost test]# docker build -t "centos7:1.0" .
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Sm7iFGIQ-1649643242601)(C:\Users\孟吉祥\AppData\Roaming\Typora\typora-user-images\image-20220408093730744.png)]
4.查看镜像发现已经创建好了
5.启动一个容器
[root@localhost test]# docker run -itd --name test02 -P centos7:1.0
89608aa358d136c3c2ee1653942c46a64f2f3f80c695b88832c9acb6a5dcd577
报这个错是因为容器装的httpd服务里的ServerName有一行给注释掉了,打开就好
方法:1.重新进入Dockerfile进行修改
[root@localhost test]# vim Dockerfile
2.启动一个新的容器
[root@localhost test]# docker run -itd --name test03 -P centos7:1.0
bc7806ac740b5dca6a46bcab83d2c4ef6d7368ec87d4963f6907d13f795e5c52
3.进入该容器
[root@localhost test]# docker exec -it test03 /bin/bash
4.修改里面的一个文件
[root@7e9d4a646ca5 /]# vi /etc/httpd/conf/httpd.conf
把这行打开就好
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vl4z9FdT-1649643242603)(C:\Users\孟吉祥\AppData\Roaming\Typora\typora-user-images\image-20220408095724959.png)]
5.进入Dockerfile修改
进入容器输入httpd查看是否已运行
6.在主机访问改容器
…(img-acXc0xwF-1649643242604)]
进入容器输入httpd查看是否已运行
6.在主机访问改容器