Dockerfile中COPY的用法

 

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 index.html     /var/www/html/

#暴露ssh端口

EXPOSE 80 

ENTRYPOINT ["/usr/sbin/nginx","-g", "daemon off;"]

 

 

编辑index.html

root@ubuntu:/dockerfile/df_test6#cat index.html

<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 index.html /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#

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值