我遇到了一个问题,即我的Docker文件在Docker compose之外运行良好,但是在Docker Compose中使用时,我的Nginx目标未正确安装在/usr/share/nginx/html
中。
docker-compose.yml
version: "3.7"
services:
web:
build:
context: ./web
dockerfile: Dockerfile-development
volumes:
- ./web:/web
- ./web/node_modules/
env_file:
- .env-web
nginx:
build:
context: ./web
dockerfile: Dockerfile-development
target: nginx
volumes:
- ./web/nginx/default.conf:/etc/nginx/conf.d
- ./web/build:/usr/share/nginx/html
ports:
- "80:80"
depends_on:
- web
dockerfile-development
FROM node:9.8.0 as web
ARG APP_ENV=development
WORKDIR /web
COPY package.json /web/package.json
RUN npm install
COPY . /web
RUN npm run build-development
FROM nginx:1.14 as nginx
COPY --from=web /web/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
因此,如果我在Docker之外构建并运行Dockerfile-development
,则一切正常,并且Nginx启动,但是,如果我使用docker-compose up
,则生成并运行了映像而没有错误,但是nginx找不到了在容器中。
编辑
我发现问题出在运行build-development
的{{1}}上。结果是nginx根本没有运行。无论如何,我既可以将带有watch标志的webpack都在后台运行,又可以让docker继续构建和运行nginx容器?