portainer: Failed to mount file on new stack creation

Bug description

I’m getting the following error while trying to create new stack through portainer.

portainer_1  | time="2018-07-15T19:37:20Z" level=error msg="Failed Starting taskwarriorweb : Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused \"process_linux.go:402: container init caused \\\"rootfs_linux.go:58: mounting \\\\\\\"/data/compose/1/hosts\\\\\\\" to rootfs \\\\\\\"/var/lib/docker/overlay2/2068c67764c58a607d468debca1df30a8ec965124b12305a54097eb233feb7eb/merged\\\\\\\" at \\\\\\\"/var/lib/docker/overlay2/2068c67764c58a607d468debca1df30a8ec965124b12305a54097eb233feb7eb/merged/etc/hosts\\\\\\\" caused \\\\\\\"not a directory\\\\\\\"\\\"\": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type"

I’m using repository as a source for the new stack.

docker-compose.yml

version: "2"

services:
  taskwarriorweb:
    image: zebradil/taskwarrior-web
    ports:
      - 5678:5678
    volumes:
      - ./.taskrc:/root/.taskrc
      - ./.task:/root/.task
      - ./hosts:/etc/hosts
    extra_hosts:
      - task.host.com:138.200.200.100

All the files from the volumes section are located in the same directory with docker-compose.yml. .taskrc and hosts are files, .task is a directory.

Technical details:

  • Portainer version: 1.18.1

  • Docker version (managed by Portainer): 18.05.0-ce

  • Platform (windows/linux): Linux / Centos 7

  • Command used to start Portainer (docker run -p 9000:9000 portainer/portainer): docker-compose up with the following config:

    version: '2'
    
    services:
      portainer:
        image: portainer/portainer
        command: -H unix:///var/run/docker.sock
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - portainer_data:/data
        ports:
          - 9000:9000
    
    volumes:
      portainer_data:
    

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

It would be nice if relative paths would work.

Relative paths should work when creating a stack from a git repository.

Ok, we’ll investigate.

Portainer clones a repo inside the container, or if you are using a persistent volume it will be inside that. As such with the current implementation, relative paths don’t work.

For now you can reference the full path to the directory inside /var/lib/docker/volumes/portainer_data/_data/compose/id but you will have to find the id once the repo is cloned inside the portainer volume and edit the stack to reflect this

I’ve had the same problem deploying a stack from git. In my case there was no error message, it just didn’t work.

In the end I SSH-ed onto the machine (single instance as well) and found the absolute path to the checked out files. After editing the stack in Portainer’s editor to reference the files via absolute paths (/var/lib/docker/volumes/portainer_data/_data/compose/7/...) it started working.

I made a clean example, and the error appeared again. Here is the the repo: https://github.com/Zebradil/portainer-test

In the root directory of the repo:

  • docker-compose.yml
  • hosts
  • testdir/testfile

docker-compose.yml

version: "2"

services:
  taskwarriorweb:
    image: alpine:latest
    volumes:
      - ./testdir:/root/testdir
      - ./hosts:/etc/hosts

And here are portainer logs for a stack creation:

Creating network "testingstack_default" with driver ""
time="2018-07-17T12:41:01Z" level=info msg="[0/1] [taskwarriorweb]: Starting "
Pulling taskwarriorweb (alpine:latest)...
latest: Pulling from library/alpine
8e3ba11ec2a2: Pulling fs layer
8e3ba11ec2a2: Verifying Checksum
8e3ba11ec2a2: Download complete
8e3ba11ec2a2: Pull complete
Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430
Status: Downloaded newer image for alpine:latest
time="2018-07-17T12:41:04Z" level=error msg="Failed Starting taskwarriorweb : Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused \"process_linux.go:402: container init caused \\\"rootfs_linux.go:58: mounting \\\\\\\"/data/compose/1/hosts\\\\\\\" to rootfs \\\\\\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged\\\\\\\" at \\\\\\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged/etc/hosts\\\\\\\" caused \\\\\\\"not a directory\\\\\\\"\\\"\": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type"
time="2018-07-17T12:41:04Z" level=error msg="Failed to start: taskwarriorweb : Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused \"process_linux.go:402: container init caused \\\"rootfs_linux.go:58: mounting \\\\\\\"/data/compose/1/hosts\\\\\\\" to rootfs \\\\\\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged\\\\\\\" at \\\\\\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged/etc/hosts\\\\\\\" caused \\\\\\\"not a directory\\\\\\\"\\\"\": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type"
2018/07/17 12:41:04 http error: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/data/compose/1/hosts\\\" to rootfs \\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged\\\" at \\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged/etc/hosts\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type (err=Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/data/compose/1/hosts\\\" to rootfs \\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged\\\" at \\\"/var/lib/docker/overlay2/e7201dbb44683763c692db3c8482efb8b091dcc879b8d67e5c684f07d9746c06/merged/etc/hosts\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type) (code=500)

@Zebradil btw. I just noticed that you are using compose stack instead of swarm stack. There is no config option available. You need enable Swarm mode to get that feature to use.

Problem with relative mounts is that source files/folders does not exist on folder where process are actually run and at least I don’t even know which folder they should be created.

Problem is on these relative paths which you are trying to use.

You have two options:

  1. Create create folders/files on docker host like this:
mkdir /path/to/ -p
touch /path/to/.taskrc
touch /path/to/.task
touch /path/to/hosts

and modify stack file to use bind mount using absolute paths like this:

version: "2"

services:
  taskwarriorweb:
    image: zebradil/taskwarrior-web
    ports:
      - 5678:5678
    volumes:
      - /path/to/.taskrc:/root/.taskrc
      - /path/to/.task:/root/.task
      - /path/to/hosts:/etc/hosts
    extra_hosts:
      - task.host.com:138.200.200.100
  1. Modify stack file to automatically create volume:
version: "2"

services:
  taskwarriorweb:
    image: zebradil/taskwarrior-web
    ports:
      - 5678:5678
    volumes:
      - taskwarriorweb_data:/data
    extra_hosts:
      - task.host.com:138.200.200.100

and modify your container image to look these files from /data folder.