'How to run cypress tests using browsers in docker

I am trying to run my tests using chrome instead of default electron. My docker-compose.yml is

version: '3.8'

services:
  nextjs:
    // frontend app
  e2e-chrome:
    image: "cypress/included:4.1.0"
    build: ./e2e
    networks:
      - backend_backend-lomba
    container_name: cypress-chrome
    # "cypress/included" images have entrypoint set to globally installed cypress
    # so the command can simply add any arguments
    command: "--browser chrome"
    volumes:
      - ./e2e/cypress:/cypress/cypress
      - ./e2e/cypress.json:/cypress/cypress.json
  e2e:
    image: cypress
    build: ./e2e
    container_name: cypress
    networks:
      - backend_backend-lomba
    depends_on:
      - nextjs
    # note: inside e2e container, the network allows accessing
    # "web" host under name "web"
    # so "curl http://web" would return whatever the webserver
    # in the "web" container is cooking
    # see https://docs.docker.com/compose/networking/
    environment:
      - CYPRESS_baseUrl=http://nextjs:3000
    # command: npx cypress open
    # mount the host directory e2e/cypress and the file e2e/cypress.json as
    # volumes within the container
    # this means that:
    #  1. anything that Cypress writes to these folders (e.g., screenshots,
    #     videos) appears also on the Docker host's filesystem
    #  2. any change that the developer applies to Cypress files on the host
    #     machine immediately takes effect within the e2e container (no docker
    #     rebuild required).
    volumes:
      # - ./:/cypress
      - ./e2e/cypress:/cypress/cypress
      - ./e2e/cypress.json:/cypress/cypress.json
networks:
  backend_backend-lomba:
    external: true

but when i try running docker-compose run e2e npx cypress run --headed --browser chrome if get this error

Can't run because you've entered an invalid browser name.

Browser: chrome was not found on your system or is not supported by Cypress.

Cypress supports the following browsers:
 - electron
 - chrome
 - chromium
 - chrome:canary
 - edge
 - firefox

You can also use a custom browser: https://on.cypress.io/customize-browsers

Available browsers found on your system are:
 - electron

Any feedback highly appreciated



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source