Access the directory from a remote server into a Docker container as volumes

Hi everyone, I’m seeking assistance on fetching a directory named ‘images’ from a remote server labeled ‘pc1’ as volumes. The goal is to enable the machine learning process within a Docker container to utilize this directory for read/write operations via Docker Compose. Any insights on achieving this would be greatly appreciated! Thank you!!

Issue:

While executing ‘docker-compose up’, I encountered the following error:

ERROR: for event_analysis_event_analysis_1 Cannot start service event_analysis: error while mounting volume ‘/var/lib/docker/volumes/xyz_data/_data’: failed to mount local volume: mount //IP-Address/data:/var/lib/docker/volumes/xyz_data/_data, flags: 0x1000: no such file or directory

ERROR: for event_analysis Cannot start service event_analysis: error while mounting volume ‘/var/lib/docker/volumes/xyz_data/_data’: failed to mount local volume: mount //IP-Address/data:/var/lib/docker/volumes/xyz_data/_data, flags: 0x1000: no such file or directory

ERROR: Encountered errors while bringing up the project.

Due to this issue, the application is unable to create or write to the specified path.

Docker-compose file:

version: "3"

services:
  # Service for event analysis
  event_analysis:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "5007:5007"
    volumes:
      - xyz_data:/pc1/data
      
volumes:
  xyz_data:
      name: ken_data
      external: true

Docker volume creation:

docker volume create --driver local --opt type=cifs --opt device=//IP-Address/data --opt o=uid=1025,gid=100,vers=4.0 --opt o=bind xyz_data

This can’t be right. It doesn’t make sense to use --opt type=cifs and --opt o=bind at the same time. Remove the volume again, and re-create it without these arguments: --opt o=bind

Other than that, your volume looks good to me. Though the volume name xyz_data and name: key_data do not match. Make sure name: has a name of a volume that actually exists on the docker engine.

Hi, I tried the solution you mentioned. I removed the volume and recreated it using the following command:

docker volume create --driver local --opt type=cifs --opt device=//IP-Address/data --opt o=uid=1025,gid=100,vers=4.0 xyz_data

I made sure to use the same volume name in the configuration:

# docker-compose.yml
version: "3"

services:
  # Service for event analysis
  event_analysis:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "5007:5007"
    volumes:
      - xyz_data:/pc1/data:rw

volumes:
  xyz_data:
    external: true

However, I encountered an error stating “invalid argument.” Could you please advise on a solution to resolve this issue? Thank you for your assistance.

ERROR: for event_analysis_event_analysis_1 Cannot start service event_analysis: error while mounting volume ‘/var/lib/docker/volumes/xyz_data/_data’: failed to mount local volume: mount //ip-address/data:/var/lib/docker/volumes/xyz_data/_data, data: uid=1025,gid=100,vers=4.0: invalid argument

ERROR: for event_analysis Cannot start service event_analysis: error while mounting volume ‘/var/lib/docker/volumes/xyz_data/_data’: failed to mount local volume: mount //ip-address/data:/var/lib/docker/volumes/xyz_data/_data, data: uid=1025,gid=100,vers=4.0: invalid argument
ERROR: Encountered errors while bringing up the project.

I can’t tell you why it says it is an invalid argument. I never tried to access anonymous cifs shares or vers 4.0 shares at all. I try to avoid using cifs and prefer using nfsv4 instead, as it proven to be more reliable for me.

My cifs volumes in docker compose look like this:

volumes:
  cifsvol:
    driver_opts:
      type: cifs 
      o: username=myuser,password=mypass//,uid=8001,gid=8001,vers=3.0
      device: //192.168.200.x/myshare/subpath

Works like a charm like that.

Your configuration pretty much translates to this compose configuration:

volumes:
  xyz_data:
    driver: local
    driver_opts:
      type: cifs
      device: //IP-Address/data 
      o: uid=1025,gid=100,vers=4.0 

Have you tried to mount the cifs share on the host using sudo mount -t cifs -o uid=1025,gid=100,vers=4.0 //IP-Address/data /mnt/cifs-test (of course, you need to create /mnt/cifs-test before)? If it’s working from the host, it should work as volume.

1 Like