让dockerfile覆盖卷中的文件
我有一个Dockerfile,其中包含:让dockerfile覆盖卷中的文件,docker,docker-compose,dockerfile,Docker,Docker Compose,Dockerfile,我有一个Dockerfile,其中包含: COPY config.xml /path/to/data/config.xml 当我运行容器时,我使用一个本身包含config.xml文件的卷 volume: - "/data:/path/to/data 在构建和运行容器时,我希望从映像中config.xml优先(并覆盖)装载卷中可能已经存在的副本 这可能吗?当您将卷添加到Docker服务时,卷中的数据将覆盖Docker映像中的任何现有数据。如果希望Docker图像文件可用作默认文件,则需要
COPY config.xml /path/to/data/config.xml
当我运行容器时,我使用一个本身包含config.xml
文件的卷
volume:
- "/data:/path/to/data
在构建和运行容器时,我希望从映像中config.xml
优先(并覆盖)装载卷中可能已经存在的副本
这可能吗?当您将卷添加到Docker服务时,卷中的数据将覆盖Docker映像中的任何现有数据。如果希望Docker图像文件可用作默认文件,则需要执行以下操作
- 将文件存储在Docker图像预定义文件中,即(/path/to/default)
- 将入口点添加到Docker文件中,此入口点应负责将默认文件从
复制到卷路径/path/to/default
/path/to/data
From ruby:2.4.5
COPY config.xml /path/to/default/config.xml
ENTRYPOINT [ "/docker-entrypoint.sh" ]
docker-entrypoint.sh
#!/bin/sh -e
cp -r /path/to/default/config.xml /path/to/data
exec "$@" # or replace this by the command need to run the container
一般来说,不会。但是,您可以在运行时运行命令将文件从映像中的另一个位置复制到相应的位置(这将覆盖卷中的文件)。