2

I want to create selenium hub and a pytest containers by calling a .yml file. The pytest container would call the selenium hub container to run some tests. For this I have: (a) pytest project (b) Dockerfile to create an image of the project and install python (c) Bash script that executes pytest command (d) e2e.yml file to create the pytest and selenium hub containers

How it should work: (1st step) I launch e2e.yml file (d) with the command:

docker-compose -f e2e.yml up

As a result: three containers get created: two chrome nodes and the selelium hub. After that the container with the pytest project gets created via the Dockerfile (a and b)

FROM python:3.8

COPY requirements.txt .
RUN pip3 install --no-cache-dir --user -r requirements.txt
COPY . .

(2nd step) e2e.yml file than calls the bash script (c)

#!/usr/bin/env bash
set -e

export SELENIUM_URL="http://172.24.0.2:4444"

python -m pytest

The bash script essentially calls a pytest command that starts tests, which is the desired result.

What I get: The fist step passes as desired, but when I try to execute the pytest command, python outputs an error "No such file or directory: '/dev/fd/13"

Error message:

 ==================================== ERRORS ====================================
e2e_1           | ________________________ ERROR collecting test session _________________________
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/runner.py:338: in from_call
e2e_1           |     result: Optional[TResult] = func()
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/runner.py:369: in <lambda>
e2e_1           |     call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/main.py:711: in collect
e2e_1           |     for direntry in visit(str(argpath), self._recurse):
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/pathlib.py:667: in visit
e2e_1           |     yield from visit(entry.path, recurse)
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/pathlib.py:667: in visit
e2e_1           |     yield from visit(entry.path, recurse)
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/pathlib.py:667: in visit
e2e_1           |     yield from visit(entry.path, recurse)
e2e_1           | root/.local/lib/python3.8/site-packages/_pytest/pathlib.py:652: in visit
e2e_1           |     for entry in os.scandir(path):
e2e_1           | E   FileNotFoundError: [Errno 2] No such file or directory: '/dev/fd/13'
e2e_1           | =========================== short test summary info ============================
e2e_1           | ERROR  - FileNotFoundError: [Errno 2] No such file or directory: '/dev/fd/13'

The e2e.yml file (d):

version: '3.7'

services:
  e2e:
    build:
      dockerfile: Dockerfile
      context: .
    command: bash run_test_page.sh

    depends_on:
      - 'selenium-hub'
      - 'selenium-1'
      - 'selenium-2'

    environment:
      SELENIUM_URL: 'http://172.24.0.2:4444'
    volumes:
      - type: bind
        source: ./screenshots
        target: /screenshots
      - type: bind
        source: ./junit
        target: /junit

  selenium-1:
    image: selenium/node-chrome:latest
    shm_size: '2gb'
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-2:
    image: selenium/node-chrome:latest
    shm_size: '2gb'
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:latest
    expose:
      - 4444

I don't know the meaning of thir error, but my best guess is that python is improperly installed.

  • As the log says , the code executing inside container does not the the device you are trying to use (container must contain it or it must be passed as an argument when starting it) – Ptit Xav Apr 30 '22 at 12:23
  • @PtitXav do you mean, I should add something like FROM ubuntu:latest to the Dockerfile? – Anatoly Rozhkov Apr 30 '22 at 12:30
  • 1
    Look athletic [this](https://flaviocopes.com/docker-access-files-outside-container/) and [this](https://stackoverflow.com/questions/20813486/exploring-docker-containers-file-system) . This will give you more information. – Ptit Xav Apr 30 '22 at 12:43
  • @PtitXav As I see it now, when creating the container I didn't include "my device' to it, so the script cannot run properly. Could you please, show me how to rebuild the container in a way, so all the required commponents are there? I think I can solve this two ways: copy the whole filesystem of my machine (maybe) or I can add FROM ubuntu:latest to the Dockerfile. But I don't know how to do this correctly – Anatoly Rozhkov Apr 30 '22 at 13:17
  • @PtitXav I've explored the container. It does have dev/fd folder but it is missing the 13 file. What should I do to add the 13 file to the df directory? fd dir contents: 0 1 2 255 – Anatoly Rozhkov Apr 30 '22 at 13:24
  • I do not remember exactly but I think you can add the definition of /dev/fd/13 when starting the container. You can do a lot of things when starting a container. – Ptit Xav Apr 30 '22 at 13:29
  • Check for [this](https://stackoverflow.com/questions/22907231/how-to-copy-files-from-host-to-docker-container) – Ptit Xav Apr 30 '22 at 13:31

0 Answers0