我在Windows的Docker桌面中。我正在尝试使用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
之类的不存在的源目录)时,该应用已正确提供,并且我在本地计算机上得到一个空的build文件夹(为空,因为源文件夹不存在。
但是,当我将volumes
设置为- "./build:/app"
(构建文件的正确来源)时,我不仅在本地计算机上看到一个空的build
文件夹,{容器中的{1}}文件夹也为空!
看来发生了什么事
1.构建容器,该容器在构建器中构建文件。
2.文件从构建器复制到第二个容器。
3.卷已链接,然后由于我的本地app
文件夹为空,因此容器上其链接的文件夹也为空!
我尝试重置共享驱动器凭据,但无济于事。
我该怎么做?!?!