这是项目结构。
Project
/deployment
/Dockerfile
/docker-compose.yml
/services
/ui
/widget
这是 Docker 文件
FROM node:14
WORKDIR /app
USER root
# create new user (only root can do this) and assign owenership to newly created user
RUN echo "$(date '+%Y-%m-%d %H:%M:%S'): ======> Setup Appusr" \
&& groupadd -g 1001 appusr \
&& useradd -r -u 1001 -g appusr appusr \
&& mkdir /home/appusr/ \
&& chown -R appusr:appusr /home/appusr/\
&& chown -R appusr:appusr /app
# switch to new created user so that appuser will be responsible for all files and has access
USER appusr:appusr
COPY ../services/ui/widget/ /app/
COPY ../.env /app/
# installing deps
RUN npm install
以及docker-compose
版本:"3.4"
x-env: &env
HOST: 127.0.0.1
services:
widget:
build:
dockerfile: Dockerfile
context: .
ports:
- 3002:3002
command:
npm start
environment:
<<: *env
restart: always
执行project/deplyment/docker-compose up
后,输出如下:
Step 6/8 : COPY ../services/ui/widget/ /app/
ERROR: Service 'widget' failed to build : COPY failed: forbidden path outside the build context: ../services/ui/widget/ ()
我是否设定了错误的上下文?
Dockerfile
中,在WORKDIR /app
之前添加COPY . /app
,以确保文件被复制。 - SaeedERROR: Duplicate mount points:
的错误。这是我的代码: volumes: - ./build:/usr/src/app/ - ./api/database_changes:/usr/src/app/ - J.Do/usr/src/app/
)。你应该将其中一个更改为另一个路径。 - Saeed