zoukankan      html  css  js  c++  java
  • dockerfile,拷贝文件夹到镜像中(不是拷贝文件夹中的内容到镜像)

    背景说明

    今天在通过dockerfile将文件夹拷贝到镜像的时候发现,是把文件夹下的内容拷贝进去了

    dockerfile如下

    from xxxxx:81/xxxxxx/datafusion:20201208184148
    run rm -rf /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static
    copy static /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/
    

    注意:构建完镜像,运行之后发现是把本地static目录下的内容拷贝到classes目录下了,本意是要将static拷贝到classes下成为classes/static
    docker运行结果如下:

    [091a0c9e4523 root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]# ls -ltr
    total 24
    drwxr-xr-x 3 root root   36 Dec  8 18:41 templates
    -rw-r--r-- 1 root root 2710 Dec  8 18:41 sdk.properties
    drwxr-xr-x 2 root root   34 Dec  8 18:41 properties
    -rw-r--r-- 1 root root  179 Dec  8 18:41 oss.properties
    -rw-r--r-- 1 root root 2888 Dec  8 18:41 logback-spring.xml
    -rw-r--r-- 1 root root  200 Dec  8 18:41 intellit.properties
    drwxr-xr-x 2 root root   96 Dec  8 18:41 i18n
    drwxr-xr-x 2 root root   24 Dec  8 18:41 db
    drwxr-xr-x 4 root root  223 Dec  8 18:41 config
    drwxr-xr-x 3 root root   20 Dec  8 18:41 com
    -rw-r--r-- 1 root root 1501 Dec  8 18:41 banner.txt
    -rw-r--r-- 1 root root  465 Dec  8 18:41 application.properties
    drwxr-xr-x 2 root root   48 Dec  8 18:41 META-INF
    drwxr-xr-x 5 root root   59 Dec  9 09:02 datafusion
    [091a0c9e4523 root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]#   #并没有把static目录拷贝进来
    

    实现方法

    copy时指定镜像中的目录

    dockerfile修改如下

    from xxxxx:81/xxxxxx/datafusion:20201208184148
    run rm -rf /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static
    copy static /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static    #加上镜像内的static目录,虽然镜像中的目录已经被删除
    

    构建,运行新的镜像

    [ec5dbacdec93 root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]# ls -ltr
    total 24
    drwxr-xr-x 3 root root   36 Dec  8 18:41 templates
    -rw-r--r-- 1 root root 2710 Dec  8 18:41 sdk.properties
    drwxr-xr-x 2 root root   34 Dec  8 18:41 properties
    -rw-r--r-- 1 root root  179 Dec  8 18:41 oss.properties
    -rw-r--r-- 1 root root 2888 Dec  8 18:41 logback-spring.xml
    -rw-r--r-- 1 root root  200 Dec  8 18:41 intellit.properties
    drwxr-xr-x 2 root root   96 Dec  8 18:41 i18n
    drwxr-xr-x 2 root root   24 Dec  8 18:41 db
    drwxr-xr-x 4 root root  223 Dec  8 18:41 config
    drwxr-xr-x 3 root root   20 Dec  8 18:41 com
    -rw-r--r-- 1 root root 1501 Dec  8 18:41 banner.txt
    -rw-r--r-- 1 root root  465 Dec  8 18:41 application.properties
    drwxr-xr-x 2 root root   48 Dec  8 18:41 META-INF
    drwxr-xr-x 3 root root   24 Dec  9 13:00 static        #已经成功把static目录拷贝进来了,进入到镜像中也是static这个目录,而不是把目录中的内容拷贝进来
    [ec5dbacdec93 root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]#
    

    通过add命令,指定镜像中的目录

    dockerfile如下

    from 172.20.59.71:81/c87e2267-1001-4c70-bb2a-ab41f3b81aa3/datafusion:20201208184148
    run rm -rf /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static
    add static /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static
    

    运行结果:

    [fb235c3c32af root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]# ls -ltr
    total 24
    drwxr-xr-x 3 root root   36 Dec  8 18:41 templates
    -rw-r--r-- 1 root root 2710 Dec  8 18:41 sdk.properties
    drwxr-xr-x 2 root root   34 Dec  8 18:41 properties
    -rw-r--r-- 1 root root  179 Dec  8 18:41 oss.properties
    -rw-r--r-- 1 root root 2888 Dec  8 18:41 logback-spring.xml
    -rw-r--r-- 1 root root  200 Dec  8 18:41 intellit.properties
    drwxr-xr-x 2 root root   96 Dec  8 18:41 i18n
    drwxr-xr-x 2 root root   24 Dec  8 18:41 db
    drwxr-xr-x 4 root root  223 Dec  8 18:41 config
    drwxr-xr-x 3 root root   20 Dec  8 18:41 com
    -rw-r--r-- 1 root root 1501 Dec  8 18:41 banner.txt
    -rw-r--r-- 1 root root  465 Dec  8 18:41 application.properties
    drwxr-xr-x 2 root root   48 Dec  8 18:41 META-INF
    drwxr-xr-x 3 root root   24 Dec  9 13:03 static  #static目录已经被拷贝进来了。
    [fb235c3c32af root:/usr/local/tomcat/webapps/datafusion/WEB-INF/classes]# 
    
  • 相关阅读:
    LeetCode | Remove Duplicates from Sorted List
    LeetCode | Remove Duplicates from Sorted Array
    LeetCode | Merge Sorted Array
    opencv的配置、使用
    LeetCode | Merge Two Sorted Lists
    LeetCode | Minimum Depth of Binary Tree
    LeetCode | Same Tree
    LeetCode | Maximum Depth of Binary Tree
    LeetCode | Insertion Sort List
    python运算符优先级
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/14107969.html
Copyright © 2011-2022 走看看