【发布时间】:2020-09-18 09:50:44
【问题描述】:
我正在使用 Docker-compose 将我的 webapp 拆分为两个容器。 项目文件夹层次结构如下所示:
- 应用/
- .git/
- 前端/
- Dockerfile
- 后端/
- Dockerfile
- docker-compose.yml
我使用 VSCode 上的 Remote-Containers 扩展直接在我的容器中工作,这样我就不必为每次更改都重新构建我的容器。我也想在我的容器中使用 git。但我不确定如何将 .git/ 文件夹复制到我的容器中,因为它在 Dockerfile 的上下文之外。
我的 docker-compose.yml:
services:
angular: # name of the first container
build: ./frontend
ports:
- "8080:8080"
express: # name of the second container
build: ./backend
ports:
- "8081:8081"
我的前端/Dockerfile:
FROM node:10.18.0-alpine AS build
WORKDIR /usr/src/app
COPY ./../.git . # doesn't work!
# copy package.json & install dependencies
COPY package.json .
RUN npm cache clean --force
RUN npm install
# copy files to /usr/src/app
COPY . .
EXPOSE 8080
# call start script from package.json
CMD ["npm","start"]
【问题讨论】: