Dockerfile中COPY的用法
编辑Dockerfile
root@ubuntu:~#cd /dockerfile/df_test6
root@ubuntu:/dockerfile/df_test6# vim Dockerfile
root@ubuntu:/dockerfile/df_test6#cat Dockerfile
# 设置基本的镜像,后续命令都以这个镜像为基础
FROM ubuntu
# 作者信息
MAINTAINER shangwu
# RUN命令会在上面指定的镜像里执行任何命令
RUN apt-get update
RUN apt-get install -y nginx
COPY /var/www/html/
#暴露ssh端口
EXPOSE 80
ENTRYPOINT ["/usr/sbin/nginx","-g", "daemon off;"]
编辑
root@ubuntu:/dockerfile/df_test6#cat
<html>
<head>
<title>Page added in Dcokerfile</title>
</head>
<body>
<h1>I'm page in df_test6</h1>
</body>
</html>
root@ubuntu:/dockerfile/df_test6#
构建镜像df_test6容器
root@ubuntu:/dockerfile/df_test6#docker build -t="df_test6" .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu
--->dc8dd8718e57
Step 1 : MAINTAINER shangwu
--->Using cache
--->cd3d00722426
Step 2 : RUN apt-get update
--->Using cache
--->0096fe9ac7c4
Step 3 : RUN apt-get install -y nginx
---> Usingcache
--->c8b93cc747d7
Step 4 : COPY /var/www/html/
--->71c8ceeb0a99
Removing intermediate container db6abecefc2f
Step 5 : EXPOSE 80
--->Running in 8245556c7cf3
--->5d3e03dab93c
Removing intermediate container 8245556c7cf3
Step 6 : ENTRYPOINT /usr/sbin/nginx -g daemon off;
--->Running in 9ff6dc080bbc
--->eed50c676721
Removing intermediate container 9ff6dc080bbc
Successfully built eed50c676721
root@ubuntu:/dockerfile/df_test6#
启动容器
root@ubuntu:/dockerfile/df_test6#docker run -d -p 80 --name cp_test df_test6
9e647530168faed028febd6560006c5c26227af28314849905a9ad4fb2a8c78c
root@ubuntu:/dockerfile/df_test6#
查看容器
root@ubuntu:/dockerfile/df_test6# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9e647530168f df_test6:latest "/usr/sbin/nginx -g 4seconds ago Up 4 seconds 0.0.0.0:32770->80/tcp cp_test
root@ubuntu:/dockerfile/df_test6#
访问容器中的nginx
root@ubuntu:/dockerfile/df_test6# curlhttp://127.0.0.1:32770
<html>
<head>
<title>Page added in Dcokerfile</title>
</head>
<body>
<h1>I'm page in df_test6</h1>
</body>
</html>
root@ubuntu:/dockerfile/df_test6#