David F. B.
David F. B.

Reputation: 73

Cypress cannot run in Docker container

I have a web application running in a Docker container. From my understanding, using the ‘cypress/base’ image should provide the necessary dependencies. However, trying to start the Cypress tests from an attached shell (run with headless), results in the following output:

Unhandled rejection Error: Your system is missing the dependency: Xvfb

Install Xvfb and run Cypress again.

Read our documentation on dependencies for more information:

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.

----------

Error: spawn Xvfb ENOENT

----------

Platform: linux (Debian - 10.11)
Cypress Version: 8.5.0
    at /app/node_modules/cypress/lib/errors.js:328:17
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/app/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._resolveCallback (/app/node_modules/bluebird/js/release/promise.js:466:57)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:559:17) 
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)

Installing Xvfb manually does not resolve the issue; it only results in another error saying Cypress’s dependencies could not be resolved.

Dockerfile:

FROM node:16

RUN mkdir /app

WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn
RUN npx browserslist@latest --update-db
COPY . .


CMD ["yarn", "start"]

docker-compose.yml:

version: "3"

services:
  ponder:
    image: cypress/base:16
    container_name: myApplication
    build: ./
    volumes:
      - ./src:/app/src
      - ./public:/app/public
      - ./package.json:/app/package.json
      - /app/node_modules
    ports:
      - 3001:3000
    stdin_open: true

Thoughts?

Edit:

Xvfb was installed manually by running apt-get update, then apt-get install xvfb. Attempting to run Cypress after this, gives:

Unhandled rejection Error: Cypress failed to start.

This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies

Please refer to the error below for more details.

----------

/root/.cache/Cypress/8.5.0/Cypress/Cypress: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

----------

Platform: linux (Debian - 10.11)
Cypress Version: 8.5.0
    at /app/node_modules/cypress/lib/errors.js:328:17
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/app/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._resolveCallback (/app/node_modules/bluebird/js/release/promise.js:466:57)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:559:17)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/app/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._resolveCallback (/app/node_modules/bluebird/js/release/promise.js:466:57)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:559:17)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)

Upvotes: 2

Views: 4319

Answers (2)

Zakaria
Zakaria

Reputation: 1013

You need to install dependencies. https://docs.cypress.io/guides/continuous-integration/introduction#Dependencies

apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb

Upvotes: 2

djangofan
djangofan

Reputation: 29669

Instead of FROM node:16, try using FROM cypress/included . that image comes with node 16 already and browsers pre-installed. NOTE: the image might be a lot larger.

Nice attempt but you are overdoing it a little.

Upvotes: 1

Related Questions