docker 容器“将构建”,但由于某种原因“将无法运行”。我正在尝试解决这个问题,但我认为我需要用新的眼光来看待它。
这是代码:
Docker 文件:
FROM cypress/included:6.8.0
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress
docker 忽略文件
node_modules
docker-compose.yml 文件
version: '3'
services:
e2e:
image: cypress
build: .
container_name: cypress
command:
npx cypress run
我的终端收到以下错误消息
docker-compose -f docker-compose.yml up
Building e2e
[+] Building 293.8s (9/10)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/cypress/included:6.8.0 0.0s
=> [1/6] FROM docker.io/cypress/included:6.8.0 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 1.14kB 0.0s
=> CACHED [2/6] WORKDIR /app 0.0s
=> [3/6] COPY . /app 0.1s
=> [4/6] RUN npm install 292.0s
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.4s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.387 /bin/sh: 1: /app/node_modules/.bin/: Permission denied
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 126
ERROR: Service 'e2e' failed to build
xxx-MacBook-Air CypressDocker %
@mosaad。我刚刚尝试了你的答案。但是我收到以下错误消息
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.8s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.705 /bin/sh: 1: /app/node_modules/.bin/: not found
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 127
ERROR: Service 'e2e' failed to build
最佳答案
您应该在npm install
之后复制,以便node_modules也被复制。
这应该有效:
FROM cypress/included:6.8.0
WORKDIR /app
RUN npm install
COPY . /app
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress
关于docker - 在 Cypress 中运行 Docker 容器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67178624/