Selenium docker video doesn't work by network_mode as host in docker-compose

1.5k views Asked by At

In docker-compose file, I set contained with chrome-standalone image and another node (named test) as test runner. Cloudbuild.yaml file triggers test and it works.

Here is the docker-compose file:

version: "3"
services:
  selenium:
    image: selenium/standalone-chrome:4
    volumes:
    - /dev/shm:/dev/shm
    network_mode: host

  test:
    image:  node:16-alpine
    entrypoint:
    - sh
    - -c
    - |-
      cd /test
      npm install
      sleep 3
      npm run test
    volumes:
    - .:/test
    depends_on:
    - selenium
    network_mode: host

I cannot add selenium video recorder service.

chrome_video:
    image: selenium/video:ffmpeg-4.3.1-20210804
    volumes:
      - /Users/videos:/videos 
    depends_on:
      - selenium
    environment:
      - DISPLAY_CONTAINER_NAME=selenium
      - FILE_NAME=chrome_video.mp4

Adding network_mode:host as an argument to chrome_video doesn't work. They don't get each other's ping.

After chrome_video container is initialised, the log file of it:

2021-08-20 16:23:05,910 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.

2021-08-20 16:23:05,913 INFO supervisord started with pid 10

2021-08-20 16:23:06,915 INFO spawned: 'video-recording' with pid 12

2021-08-20 16:23:06,920 INFO spawned: 'video-ready' with pid 13

Checking if the display is open...

2021-08-20 16:23:06,924 INFO success: video-recording entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

2021-08-20 16:23:06,924 INFO success: video-ready entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
Waiting before next display check...

Waiting before next display check...

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers

built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)

configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-fontconfig --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-postproc --enable-small --enable-version3 --enable-libbluray --enable-libzmq --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-libopenjpeg --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-libsrt --enable-libaribb24 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib

libavutil 56. 51.100 / 56. 51.100

libavcodec 58. 91.100 / 58. 91.100

libavformat 58. 45.100 / 58. 45.100

libavdevice 58. 10.100 / 58. 10.100

libavfilter 7. 85.100 / 7. 85.100

libavresample 4. 0. 0 / 4. 0. 0

libswscale 5. 7.100 / 5. 7.100

libswresample 3. 7.100 / 3. 7.100

libpostproc 55. 7.100 / 55. 7.100

[x11grab @ 0x55f0bf04fb80] Cannot open display selenium:99.0, error 1.

selenium:99.0: Input/output error

2021-08-20 16:23:32,692 INFO exited: video-recording (exit status 1; not expected)Waiting before next display check...

Waiting before next display check...


Waiting before next display check...

Waiting before next display check...

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers

built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)

configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-fontconfig --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-postproc --enable-small --enable-version3 --enable-libbluray --enable-libzmq --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-libopenjpeg --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-libsrt --enable-libaribb24 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib

libavutil 56. 51.100 / 56. 51.100

libavcodec 58. 91.100 / 58. 91.100

libavformat 58. 45.100 / 58. 45.100

libavdevice 58. 10.100 / 58. 10.100

libavfilter 7. 85.100 / 7. 85.100

libavresample 4. 0. 0 / 4. 0. 0

libswscale 5. 7.100 / 5. 7.100

libswresample 3. 7.100 / 3. 7.100

libpostproc 55. 7.100 / 55. 7.100

[x11grab @ 0x55f0bf04fb80] Cannot open display selenium:99.0, error 1.

selenium:99.0: Input/output error

2021-08-20 16:23:32,692 INFO exited: video-recording (exit status 1; not expected)



 Waiting before next display check...
    
    Waiting before next display check...
    
    Waiting before next display check...
    
    Waiting before next display check...
    
    ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
    
    built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
    
    configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-fontconfig --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-postproc --enable-small --enable-version3 --enable-libbluray --enable-libzmq --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-libopenjpeg --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-libsrt --enable-libaribb24 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib
    
    libavutil 56. 51.100 / 56. 51.100
    
    libavcodec 58. 91.100 / 58. 91.100
    
    libavformat 58. 45.100 / 58. 45.100
    
    libavdevice 58. 10.100 / 58. 10.100
    
    libavfilter 7. 85.100 / 7. 85.100
    
    libavresample 4. 0. 0 / 4. 0. 0
    
    libswscale 5. 7.100 / 5. 7.100
    
    libswresample 3. 7.100 / 3. 7.100
    
    libpostproc 55. 7.100 / 55. 7.100
    
    [x11grab @ 0x55f0bf04fb80] Cannot open display selenium:99.0, error 1.
    
    selenium:99.0: Input/output error
    
    2021-08-20 16:23:32,692 INFO exited: video-recording (exit status 1; not expected)

If I edit docker-composer as below, I get video recording in expected directory, however it seems that test cannot reach the :

version: "3"
services:
  selenium:
    image: selenium/standalone-chrome:4
    volumes:
    - /dev/shm:/dev/shm

  test:
    image:  node:16-alpine
    entrypoint:
    - sh
    - -c
    - |-
      cd /test
      npm install
      sleep 3
      npm run test
    volumes:
    - .:/test
    depends_on:
    - selenium

  chrome_video:
    image: selenium/video:ffmpeg-4.3.1-20210804 
    volumes:
      - /Users/videos:/videos # /artifacts/videos:/videos
    depends_on:
      - selenium
    environment:
      - DISPLAY_CONTAINER_NAME=selenium
      - FILE_NAME=chrome_video.mp4

Error when the docker-compose file above is run:

test_1 | 1) Preliminary steps for End to End Tests test_1 | Login: test_1 | Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 test_1 | at ClientRequest. (node_modules/selenium-webdriver/http/index.js:273:15) test_1
| at ClientRequest.emit (node:events:394:28) test_1 |
at Socket.socketErrorListener (node:_http_client:447:9) test_1
| at Socket.emit (node:events:394:28) test_1 | at emitErrorNT (node:internal/streams/destroy:157:8) test_1 |
at emitErrorCloseNT (node:internal/streams/destroy:122:3) test_1
| at processTicksAndRejections (node:internal/process/task_queues:83:21) test_1 | test_1
| 2) Preliminary steps for End to End Tests test_1 |
"after each" hook for "Login": test_1 | Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 test_1 |
at ClientRequest. (node_modules/selenium-webdriver/http/index.js:273:15) test_1
| at ClientRequest.emit (node:events:394:28) test_1 |
at Socket.socketErrorListener (node:_http_client:447:9) test_1
| at Socket.emit (node:events:394:28) test_1 | at emitErrorNT (node:internal/streams/destroy:157:8) test_1 |
at emitErrorCloseNT (node:internal/streams/destroy:122:3) test_1
| at processTicksAndRejections (node:internal/process/task_queues:83:21)

Btw, all containers are in same network (common network's name is e2e-tests_default):

e2e-tests % docker network inspect e2e-tests_default -f "{{json .Containers }}" {"26858f4ebf7cda76aaa100c8f3db8df14c319a6e3d4c54f839202affde72ad11":{"Name":"e2e-tests_chrome_video_1","EndpointID":"8d3beeb215b524e573db0d6f9a001c04ba9a77823b42e10f45160868af16bd4b","MacAddress":"02:42:c0:a8:70:04","IPv4Address":"192.168.112.4/20","IPv6Address":""},"972490a8a2e94adc1cb2e73daf5c0b206a89e483330e3d736fef0eca6cd5b170":{"Name":"e2e-tests_test_1","EndpointID":"abce602dc1c22ab21b760b50aeca2a77de07304c2c7cc224a7164078f8af56bd","MacAddress":"02:42:c0:a8:70:03","IPv4Address":"192.168.112.3/20","IPv6Address":""},"9ed9962e468cba1cd0fdfe1511fc23c931fd2f0dbf6d95bdb3009809ca097939":{"Name":"e2e-tests_selenium_1","EndpointID":"448b560b932501edb66204f492af8edc38a1bd5ec0c19eb217b6d51ebf48aab0","MacAddress":"02:42:c0:a8:70:02","IPv4Address":"192.168.112.2/20","IPv6Address":""}}

Is there a way to enable video recording for this setup?

Thanks in advance.

1

There are 1 answers

2
diemol On

Unless you need a service running on the host, there is no need to use network_mode: host.

Moreover, the video container needs to know the name of the service/container where VNC is running record the stream. In this case, based on the docker-compose file you share, DISPLAY_CONTAINER_NAME=chrome should be actually DISPLAY_CONTAINER_NAME=selenium.