Docker添加文件夹,然后暴露给VOLUME
我正在使用docker-compose作为基本的web应用程序。 当图像被构build时,它将复制( ADD
)中的静态JS文件,然后构build它们。
然后我想使用VOLUME
将该目录公开到其他容器。
例如
Dockerfile
ADD ./site/static /site/static WORKDIR /site/static RUN gulp
泊坞窗,compose.yml
app: build: . volumes: - /site/static http: image: nginx volumes_from: - app
nginx.conf
location /static { alias /site/static }
(注意,这只是一个例子)
问题是,它似乎是第一次工作(即当卷不存在),但是从来没有被修改后的图像覆盖。 如果我纯粹使用Dockerfile
,可以通过在ADD
后ADD
VOLUME
来实现。
有没有办法让这个,还是我接近完全错了?
谢谢
可能的解决scheme
我可能是错的,但是我认为麻烦的是当(如果)你做的时候
docker-compose down && docker-compose up
你的容器被重新创build,新的“匿名”卷被创build。 你可以检查我的猜测运行:
docker volume ls
我会尝试使用命名卷,如下所示:
version: "2" volumes: app-volume: ~ services: app: build: . volumes: - app-volume:/site/static http: image: nginx volumes: - app-volume:/site/static
您需要docker-compose 1.6.0以上版本,并且需要Docker-compose文件版本2的版本为1.10.0+的Docker Engine。
可能的解决scheme2
只是
app: build: . volumes: - ./site/static:/site/static # maps host directory `./site/static` (relative to docker-compose.yml) to /site/static inside container http: image: nginx volumes_from: - app
并删除
ADD ./site/static /site/static
从你的Dockerfile