码迷,mamicode.com
首页 > 其他好文 > 详细

[Docker]Dockerfile定制容器

时间:2020-04-20 20:09:45      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:iat   run   file   inter   context   success   agg   roo   images   

需要部署的网页

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

[Docker]Dockerfile定制容器

标签:iat   run   file   inter   context   success   agg   roo   images   

原文地址:https://www.cnblogs.com/leoshi/p/12740014.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!