0

I am trying to run a project on docker-compose via a remote server. Everything works, but as soon as I add the item about mounting the volume, it gives an error:

Error response from daemon: invalid mount config for type "bind": invalid mount path: 'C:/Users/user/Projects/my-raspberry-test' mount path must be absolute

To run I use tools from PhpStorm.

The docker-compose.yml file itself looks like this:

version: "3"

services:
  php:
    image: php:cli
    volumes:
      - ./:/var/www/html/
    working_dir: /var/www/html/
    ports:
      - 80:80
    command: php -S 0.0.0.0:80

I checked by ssh:

  • Daemon is running,
  • Docker works (on a similar Dockerfile with the same tasks),
  • Docker-compose works (on the same file).

Also checked docker remote run using phpstorm and file:

FROM php:cli
COPY . /var/www/html/
WORKDIR /var/www/html/
CMD php -S 0.0.0.0:80

It didn’t give an error and it worked.

OS on devices:

  • PC: Windows 10
  • Server: Fedora Server

Without mounting the volume in docker-compose, everything starts. Maybe someone faced a similar problem? php for an example.

  • You are trying to mount a relative path which is invalid against a remote host. This is also what your error tells you. As far as I can remember you can only use named volumes. – The Fool Nov 01 '21 at 21:27
  • @TheFool I tried to change to absolute path `- C:/Users/user/Projects/my-raspberry-test/app/:/var/www/html/` but nothing changed – Ishi Inanis Nov 01 '21 at 21:31
  • The path you provide is a windows' path. That for sure doesnt work. Your container runs on another server. The path doesnt even exist on the server. Volumes are mounted on the host where the deamon is running. As I said, I think you can actually only use named volumes. – The Fool Nov 01 '21 at 21:32
  • 1
    Does this answer your question? [How can I mount a volume of files to a remote docker daemon?](https://stackoverflow.com/questions/51305537/how-can-i-mount-a-volume-of-files-to-a-remote-docker-daemon) – The Fool Nov 01 '21 at 21:32
  • A bit, I have a place to look to try to solve the problem. But I use docker-compose because it dynamically updates my files which I change constantly as I work. Not sure if a similar way would work as well – Ishi Inanis Nov 01 '21 at 21:52
  • Maybe I just don't know much about docker yet and that's why I just can't create a regular Dockerfile with a dynamic volume connection – Ishi Inanis Nov 01 '21 at 21:54
  • Aside from the image-building process (which is not live-reloading) Docker doesn't have any way to copy files between two physical systems. The `volumes:` local path is being interpreted as a path by the remote Docker daemon, and it doesn't make sense because it's a Windows path on a Linux system. I might delete the `volumes:` entirely to use the code built into the image, and use a local non-Docker setup for day-to-day development. – David Maze Nov 01 '21 at 21:57
  • vscode can help you with this. Its been a while but I remember that I have already developed against a remote host. I think it does some voodoo and copies your local files in a named volume. You can maybe have a look at this answer, although it requires you still to figure things out a bit. https://stackoverflow.com/questions/62817999/vs-code-attach-visual-studio-code-to-remote-container-error/62819531#62819531 – The Fool Nov 01 '21 at 21:58
  • @DavidMaze I understand correctly that if I have a real directory on the remote host on the way in the volume, then everything will work? – Ishi Inanis Nov 01 '21 at 22:06
  • Sure, but if you're going to separately copy the application source code around, it's easier to use a non-Docker native interpreter. I'd recommend using Docker's image system especially for this setup and to avoid `volumes:` for source code. – David Maze Nov 01 '21 at 23:56
  • @DavidMaze Where can you read more about this? – Ishi Inanis Nov 02 '21 at 11:04
  • Material like Docker's [Sample application](https://docs.docker.com/get-started/02_our_app/) tutorial build a self-contained image, with the code in the image, and without volumes; this would work fine with a remote Docker. – David Maze Nov 02 '21 at 11:27
  • Got it, thanks a lot – Ishi Inanis Nov 02 '21 at 13:08

1 Answers1

1

The path must be absolute for the remote host and the project data itself must be loaded there. That is, you need to upload the project to a remote host.

I corrected everything like this:

volumes:
  - /home/peter-alexeev/my-test:/var/www/html/