docker-elk icon indicating copy to clipboard operation
docker-elk copied to clipboard

Bind mounts do not work with remote Docker deamon

Open darshanchaudhary opened this issue 9 years ago • 22 comments

I am getting this when I do docker-compose up

 logger (master) ✗ dc up
Creating logger_elasticsearch_1 ... 
Creating logger_elasticsearch_1 ... error

ERROR: for logger_elasticsearch_1  Cannot start service elasticsearch: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359: container init caused \"rootfs_linux.go:54: mounting \\\"/Users/foo/bar/logger/elasticsearch/config/elasticsearch.yml\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/0b7be06fbdsadsadds5f8e14dddf0d6c632370b4299300efe5\\\" at \\\"/var/lib/docker/aufs/mnt/0b7bdsadsadasdd2235c5f8e14dddf0d6c632370b4299300efe5/usr/share/elasticsearch/config/elasticsearch.yml\\\" caused \\\"not a directory\\\"\""
: 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

ERROR: for elasticsearch  Cannot start service elasticsearch: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359: container init caused \"rootfs_linux.go:54: mounting \\\"/Users/darshanchoudhary/zinnov/logger/elasticsearch/config/elasticsearch.yml\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/0b7be06fbd6ef6b20adc69235bd2235c5f8e14dddf0d6c632370b4299300efe5\\\" at \\\"/var/lib/docker/aufs/mnt/0b7be06fbd6ef6b20adc69235bd2235c5f8e14dddf0d6c632370b4299300efe5/usr/share/elasticsearch/config/elasticsearch.yml\\\" caused \\\"not a directory\\\"\""
: 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
ERROR: Encountered errors while bringing up the project.

darshanchaudhary avatar Jun 13 '17 13:06 darshanchaudhary

@darshanchaudhary did you manage to solve this? If not could you please tell us more about your environment?

antoineco avatar Jun 19 '17 20:06 antoineco

I just cloned the repo and did docker-compose uped and got this error. I resolved it by moving all the volume statements to the in individual Dockerfiles.

darshanchaudhary avatar Jun 20 '17 01:06 darshanchaudhary

On which OS / distribution are you running Docker?

If Redhat/CentOS/Fedora it could be related to SELinux. The README provides guidance in order to deal with this.

antoineco avatar Jun 20 '17 05:06 antoineco

I was running it on Ubuntu, 16.04

darshanchaudhary avatar Jun 20 '17 06:06 darshanchaudhary

/Users/darshanchoudhary/zinnov/logger looks like a macOS path to me, not Linux.

Long story short, Docker is trying to mount a file it can not access. The information provided is insufficient for me to figure out the actual reason I'm afraid.

antoineco avatar Jun 20 '17 06:06 antoineco

The file resides on my mac, and I am mounting it on my container which runs on Linux. There isn't much info to give really, I created a Ubuntu machine using docker-machine and did a docker-compose up and got this error.

darshanchaudhary avatar Jun 20 '17 06:06 darshanchaudhary

Mounts will not work in this context, unless the /Users mountpoint is synced with your Linux machine. This can be configured in Virtualbox as far as I remember.

antoineco avatar Jun 20 '17 06:06 antoineco

Huh? 🤔
I moved the mount statements to Dockerfiles and it worked.

Can you explain what you are proposing?

darshanchaudhary avatar Jun 20 '17 06:06 darshanchaudhary

Of course, but then please let me remind you the importance of being fair to the people trying to help you, and avoid the thumb down reactions. Mentioning the docker-machine setup from the beginning could have saved me some confusion and give you the right pointers right away.


Docker is running on an Operating System (Ubuntu) which is itself running inside a VM powered by your host (Mac).

The files present on your Mac are not visible from your Linux virtual machine, they reside on a file system which is not accessible by the Docker daemon. Therefore mounting /Users will fail because this path does not exist from the standpoint of the Ubuntu box (take a look inside your VM).

Virtualbox has a feature called "Shared Folders" which lets you sync folders between your host machine (Mac) and guest machine (Ubuntu) (ref: 4.3. Shared folders). I remember that docker-machine has a flag that allows you to configure such a folder during the VM creation process, it's called --virtualbox-share-folder (source: Docker Machine VirtualBox drive).

Docker for Mac does not have this problem because it mounts the /User mountpoint from your Mac inside the VM using more complex mechanisms. There's a great blog post about it here: https://blog.docker.com/2017/05/user-guided-caching-in-docker-for-mac/ (scroll to "Bind mounts on Docker for Mac").

antoineco avatar Jun 20 '17 07:06 antoineco

Thank you for the pointers, I have since removed the thumbs down. I thought it was a thoughtless comment on your part (about the path being a macOS path)

Also, I agree that I did not provide complete information about my setup. One detail I missed is that I am using docker machine not to create a machine on my PC, but on AWS. I used the amazonec2 adapter to spawn up an Ubuntu instance there and docker-composeed.

The directory would not exist there (as you pointed out), but that is the reason we are mounting it in the docker-compose.yml file, isn't it? The reason I opened the issue is, I cloned the repo, spun up an amazon ec2 ubuntu instance and did dc up and it did not work. It failed with the error I pasted 🔝

darshanchaudhary avatar Jun 20 '17 07:06 darshanchaudhary

Great, much clearer now, I appreciate the details :+1:

As you said mounting the files on a remote machine makes it even more complicated than on the local host. Unfortunately docker volumes do not work like the COPY statement you probably used in your Dockerfile. Volumes are created/mounted during the container creation (docker create/run), as opposed to the image creation, so the files must really be physically accessible to the Docker daemon at any time.

Some solutions like rsync or sshfs exist, but I'd rather push the config to the image exactly like you did, or use some configuration management system to keep the conf in sync if you run at larger scale (and adjust the compose file to use that location).

I don't think Anthony (the author) had that use case in mind, so it's good to hear about it so that we can mention it in the docs.

antoineco avatar Jun 20 '17 08:06 antoineco

The reason I opened the issue is, I cloned the repo, spun up an amazon ec2 ubuntu instance and did dc up and it did not work. It failed with the error I pasted

The goal of this repository is to manage a local ELK stack. I'd recommend the automation of git clone + docker-compose on the remote instance if you want to use this repository.

@antoineco this might need some clarification in the README indeed.

deviantony avatar Jul 02 '17 06:07 deviantony

(moved to a new issue by @antoineco)

brianjill avatar Jul 14 '17 13:07 brianjill

@brianjill this is a different issue, let's continue the discussion in #150

antoineco avatar Jul 14 '17 14:07 antoineco

@deviantony are you saying that deploying this to AWS ECS is a bad idea?

I am attempting to do this very thing - I have compiled each individual Dockerfile into an image, pushed it to a registry, and have created an ecs task definition from the compose file. however, I get this same error when attempting to launch the containers.

Any idea how I would go about launching this on AWS? I understand why this doesn't work, but can't come up with a solution.

ianseyer avatar Aug 11 '17 16:08 ianseyer

Either:

  • Bake the configuration files inside the images
  • Push the configuration files to your remote Docker hosts

antoineco avatar Aug 11 '17 17:08 antoineco

@ianseyer as @antoineco said, I'd clone the git repository directly on the Docker host.

deviantony avatar Aug 14 '17 07:08 deviantony

Any interest in a production version of this that copies the files to the images rather than linking the files using volume?

dcunited08 avatar Nov 21 '17 18:11 dcunited08

@dcunited08 not sure if that would make it "production-ready", Docker Compose is a tool for prototyping, not managing the build of Docker images.

The purpose of this repo is exactly to be hackable/extendable, for the case you're describing it should be enough to add a COPY statement inside the provided Dockerfiles. Of course you have to tag and push the images yourself afterwards.

antoineco avatar Nov 24 '17 14:11 antoineco

[Windows] So I had the same issue. This is caused sometimes because of some weird docker error. I did the following to make it working again:

Under the settings section of the docker windows software, you may have to unshare, share the drive again, re-enter credentials.

vignesh380 avatar Apr 06 '18 22:04 vignesh380