docker - 在 Cypress 中运行 Docker 容器时出现问题

标签 docker docker-compose continuous-integration automated-tests cypress

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/

相关文章:

docker - 无法将 Docker Volume 目录的所有者更改为非 root 用户

node.js - 使用 docker compose 运行 Node 容器时出错

c# - 如果 NDepend 查询引发警告,我如何自动使 nant 构建失败

git - 如何手动解密通过 git crypt 加密的文件

docker - 如何使用 docker-compose 在 docker 内挂载 AWS EFS?

Jenkins:Pipeline 可选的手动阶段,即不阻塞任何代理

mysql - Docker compose.Networks。 Spring Boot 与 MySQL 连接

django - 无法在 postgres docker 容器中对用户进行身份验证

java - 使用相同的镜像名称更新 kubernetes 部署

amazon-web-services - 如何将Amazon ECS添加到我已经创建的非默认VPC中?