[Docker]Dockerfile定制容器
作者:互联网
需要部署的网页
cat > /usr/local/docker/myshop/index.jsp <<'EOF'
Hello World !
EOF
创建容器配置文件
mkdir -p /usr/local/docker/myshop
cat > /usr/local/docker/myshop/Dockerfile <<'EOF'
FROM tomcat:latest
# 创建文件夹
RUN mkdir /usr/local/tomcat/webapps/ROOT
# 复制文件
COPY index.jsp /usr/local/tomcat/webapps/ROOT
EOF
创建容器
[root@Proxy myshop]# docker build -t myshop .
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM tomcat:latest
---> 31a47677561a
Step 2/3 : RUN mkdir /usr/local/tomcat/webapps/ROOT
---> Running in 78de34ca9ae8
Removing intermediate container 78de34ca9ae8
---> 7fdc8ab7508e
Step 3/3 : COPY index.jsp /usr/local/tomcat/webapps/ROOT
---> 5eba0cd03308
Successfully built 5eba0cd03308
Successfully tagged myshop:latest
查看镜像
[root@Proxy myshop]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myshop latest 2b6a97a4c5be 56 seconds ago 529MB
运行自定义的容器
[root@Proxy myshop]# docker run -p 8080:8080 -d myshop
42111bdab34e172a777fde5d310ed5f251c09bff46c400fbf3f5b929d2321f1c
Dockerfile上下文
在当前目录下打包给docker进程,需要将所有待打包文件放置在此路径下
[root@Proxy myshop]# tree
.
├── Dockerfile
└── pages
└── index.jsp
1 directory, 2 files
修改配置文件
[root@Proxy myshop]# cat > /usr/local/docker/myshop/Dockerfile <<'EOF'
FROM tomcat:latest
# 创建文件夹
RUN mkdir /usr/local/tomcat/webapps/ROOT
# 复制文件
COPY pages/index.jsp /usr/local/tomcat/webapps/ROOT
EOF
重新构建容器
[root@Proxy myshop]# docker build -t myshop .
Sending build context to Docker daemon 3.584kB
Step 1/3 : FROM tomcat:latest
---> 31a47677561a
Step 2/3 : RUN mkdir /usr/local/tomcat/webapps/ROOT
---> Using cache
---> 6acd843144d1
Step 3/3 : COPY pages/index.jsp /usr/local/tomcat/webapps/ROOT
---> 790739f2e70f
Successfully built 790739f2e70f
Successfully tagged myshop:latest
END
标签:容器,local,Step,myshop,usr,Docker,Dockerfile,docker,Proxy 来源: https://www.cnblogs.com/leoshi/p/12740014.html