英文:
Docker Volume with specified path not populated from image
问题
我的 Docker 镜像包含位于目录 /data 中的文件。
当我运行带有命名或未命名卷的 Docker 容器,并将其关联到该目录时,卷会被从镜像中填充文件(这是应该的)。
但是,当我尝试将卷放置到特定路径时,如下所示:
volumes:
- ./data:/data
主机目录 ./data 不会从镜像中填充文件,它是空的(但从容器中可以访问)。是否有一些关于创建命名、未命名卷和特定主机路径卷的差异可以解释这种行为?
我的 Dockerfile:
FROM hypriot/rpi-alpine
RUN apk update && \
apk upgrade && \
apk add --no-cache bash minidlna && \
rm -rf /var/cache/apk/*
RUN mkdir /data && \
mkdir /data/log && \
mkdir /data/db
COPY minidlna.conf /data/minidlna.conf
COPY minidlna.conf /minidlna.conf
COPY entrypoint.sh /entrypoint.sh
VOLUME ["/data"]
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
和 docker-compose.yml:
version: "3"
services:
minidlna:
image: silvan85/rpi-minidlna
volumes:
- ./data:/data
- /media/ExternalHDD/media:/media
network_mode: "host"
restart: unless-stopped
英文:
My docker image contain files in directory /data
When I run docker container with named or unnamed volume associated with this directory volume is populated with files from image (as it sould be).
But when I try to put volume to specific path like:
volumes:
- ./data:/data
Host directory ./data is not populated witch files from image it is empty. (but accessible from container).
Is there some difference between creation of named, unnamed volumes and volumes in specific host path that explains this behavior?
My dockrefile:
FROM hypriot/rpi-alpine
RUN apk update && \
apk upgrade && \
apk add --no-cache bash minidlna && \
rm -rf /var/cache/apk/*
RUN mkdir /data %% \
mkdir /data/log && \
mkdir /data/db
COPY minidlna.conf /data/minidlna.conf
COPY minidlna.conf /minidlna.conf
COPY entrypoint.sh /entrypoint.sh
VOLUME ["/data"]
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
and docker-compose.yml
version: "3"
services:
minidlna:
image: silvan85/rpi-minidlna
volumes:
- ./data:/data
- /media/ExternalHDD/media:/media
network_mode: "host"
restart: unless-stopped
答案1
得分: 0
当你将主机目录挂载到容器中时,主机目录的内容会覆盖容器的内容。
英文:
When you mount a host directory into container, the contents of host directory shadow the contents of container.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论