【发布时间】:2019-11-08 19:22:26
【问题描述】:
我在 Docker Desktop for Windows 中。我正在尝试使用 docker-compose 作为构建容器,它在其中构建我的代码,然后代码位于我的本地构建文件夹中。构建过程肯定是成功的;当我exec 进入我的容器时,文件就在那里。但是,我的本地文件夹没有任何反应——没有创建 build 文件夹。
docker-compose.yml
version: '3'
services:
front_end_build:
image: webapp-build
build:
context: .
dockerfile: Dockerfile
ports:
- 5000:5000
volumes:
- "./build:/srv/build"
Dockerfile
FROM node:8.10.0-alpine
EXPOSE 5000
# add files from local to container
ADD . /srv
# navigate to the directory
WORKDIR /srv
# install dependencies
RUN npm install --pure-lockfile --silent
# build code (to-do: get this code somewhere where we can use it)
RUN npm run build
# install 'serve' and launch server.
# note: this is just to keep container running
# (so we can exec into it and check for the files).
# once we know that everything is working, we should delete this.
RUN npx serve -s -l tcp://0.0.0.0:5000 build
我还尝试删除为文件夹提供服务的最后一行。然后我确实得到了一个构建文件夹,但是那个文件夹是空的。
更新: 我还尝试了多阶段构建:
FROM node:12.13.0-alpine AS builder
WORKDIR /app
COPY . .
RUN yarn
RUN yarn run build
FROM node:12.13.0-alpine
RUN yarn global add serve
WORKDIR /app
COPY --from=builder /app/build .
CMD ["serve", "-p", "80", "-s", "."]
当我的卷未设置(或设置为诸如 ./build:/nonexistent 之类的不存在的源目录)时,应用程序会正确提供,并且我在本地计算机上得到一个空的构建文件夹(空的,因为源文件夹不存在)。
但是,当我将 volumes 设置为 - "./build:/app"(构建文件的正确来源)时,我不仅在本地计算机上得到了一个空的 build 文件夹,而且在容器中的 app 文件夹也是空的!
似乎正在发生的事情类似于
1. Container被构建,它在builder中构建文件。
2. 文件从生成器复制到第二个容器。
3.volumes被链接了,然后因为我本地的build文件夹是空的,它在容器上的链接文件夹也变成了空!
我已尝试重置我的共享云端硬盘凭据,但无济于事。
我该怎么做?!?!
【问题讨论】:
标签: docker docker-compose dockerfile docker-volume