How to configure a shared volume between containers

Viewed 145

One container contains a test suite, and one container contains a webdriver. When the webdriver downloads something (yes, I have to do this, other things are checked for ContentType using a HttpURLConnection), I'd like the test suite to be able to check if that downloaded file exists.

The test suite checks in the projet's downloads subdirectory, and the webdriver has been given a download path of /home/seluser.

version: "3.7"

services:
  suite:
    build: .
    command: >
      mvn
      -Dbrowser=chrome_headless_remote
      -Dbrowser_url=http://chrome:4444/wd/hub
      -Dcucumber.filter.tags="${TAGS}"
      test
    volumes:
      - shared:${PWD}/downloads
    depends_on:
      - chrome

  chrome:
    image: seleniarm/standalone-chromium:4.0.0-beta-1-20210215
    container_name: chromium-m1
    shm_size: 2gb
    ports:
      - "4444:4444"
    volumes:
      - shared:/home/seluser/

volumes:
  shared:

❯ docker volume inspect drt_shared
[
    {
        "CreatedAt": "2021-09-08T12:15:26Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "drt",
            "com.docker.compose.version": "2.0.0",
            "com.docker.compose.volume": "shared"
        },
        "Mountpoint": "/var/lib/docker/volumes/drt_shared/_data",
        "Name": "drt_shared",
        "Options": null,
        "Scope": "local"
    }
]

In suite, the directory is an existing directory copied into the image. It searches for the file in System.getProperty("user.dir") + "/downloads". In chrome, I've selected the home directory of the user selected when I log into the container.

If I use bind mounts to point to the host fs, it works as expected, but if I interpreted the Docker documentation correctly, it seems it should be possible to have that shared directory handled by docker compose.

I'm not sure how I can exactly find the problem with this. I see from the console that the downloaded file is in fact present in /home/seluser in chrome, so why can't the test suite see it? How do I start to diagnose this? Is what I want at all possible?

1 Answers

This works for me.

version: "3.7"

services:
  suite:
    build: .
    command: >
      mvn
      -Dbrowser=chrome_headless_remote
      -Dbrowser_url=http://chrome:4444/wd/hub
      -Dcucumber.filter.tags="${TAGS}"
      test
    volumes:
      - type: volume
        source: shared
        target: /downloads
    depends_on:
      - chrome

  chrome:
    image: seleniarm/standalone-chromium:4.0.0-beta-1-20210215
    container_name: chromium-m1
    shm_size: 2gb
    ports:
      - "4444:4444"
    volumes:
      - type: volume
        source: shared
        target: /home/seluser

volumes:
  shared:

I think this is what's happening (someone please confirm or correct):

suite:volumes When creating an image from a directory, that directory goes into the root of the container. So /downloads is from that root in that container. The test suite checks this location.

chrome:volumes The webdriver is told to save the file in this location. It's just the home directory.

So in our test suite, the webdriver is told to save files in the home directory of that container's user (/home/seluser). The test suite then checks for files in its own /downloads directory.

Related