Top

Docker-image(Dockerfile)

自己创建镜像

我的环境是Centos7.4!1台服务器:Server

192.168.237.128-server
↓操作
1.先做好自己的Dockerfile文件. 2.使用build命令将Dockerfile文件生成镜像. 3.镜像默认放在images列表中,可直接使用. https://www.cnblogs.com/weifeng1463/p/10277178.html

1. 制作Dockerfile

↓先下载index文件到/Dockerfile.
[root@server ~]# wget http://www.baidu.com -P /Dockerfile/
↓创建Dockerfile文件.
[root@server ~]# mkdir /Dockerfile && vim /Dockerfile/Dockerfile
1
2
3
4
5
FROM docker.io/nginx:latest						#基础镜像:如果本地没有就去官网下载.
MAINTAINER www.hyqie.com 2019-04-10 #指定维护人信息.
COPY index.html /usr/share/nginx/html/ #复制Dockerfile文件下目录里的index.html到容器中的/usr/share/nginx/html上.
EXPOSE 80 #声明镜像内服务所监听的端口.
CMD /bin/bash #镜像启动成容器时运行的命令(我这里用的/bin/bash,如果要启动nginx可以使用后面的方式允许:docker run -itd -p 80:80 nginx:v2 /bin/bash -c "exec nginx -g 'daemon off;'"

2. 使用Dockerfile文件生成镜像

[root@server ~]# docker build -t nginx:v2 /Dockerfile/
Sending build context to Docker daemon  5.12 kB
Step 1/5 : FROM docker.io/nginx:latest
 ---> 2bcb04bdb83f
Step 2/5 : MAINTAINER www.hyqie.com 2019-04-10
 ---> Using cache
 ---> 1f2d1b277564
Step 3/5 : COPY index.html /usr/share/nginx/html/
 ---> 0b897b548970
Removing intermediate container ccd9c7a76aff
Step 4/5 : EXPOSE 80
 ---> [Warning] IPv4 forwarding is disabled. Networking will not work.
 ---> Running in c0f0b7b1601c
 ---> 985ec426a55e
Removing intermediate container c0f0b7b1601c
Step 5/5 : CMD /bin/bash
 ---> [Warning] IPv4 forwarding is disabled. Networking will not work.
 ---> Running in 45cf9da3e9da
 ---> fc8886dfac3b
Removing intermediate container 45cf9da3e9da
Successfully built fc8886dfac3b 

3. 测试

↓遇到下面的报错就将转发开启.
[root@server ~]# docker run --restart=always -itd -p 80:80 nginx:v2 WARNING: IPv4 forwarding is disabled. Networking will not work. a9279733c724234fb6a27dc28f078e1dbdda259d33270d1543be6fed99e55804
↓开启后启动容器并允许nginx.
[root@server ~]# docker run --restart=always -itd -p 80:80 nginx:v2 52431bd86cb03d581305966aa7466677d5d77a32f9faa7677823b9e4daba9a73 [root@server ~]# docker exec a9279733c724 nginx 无法显示