2
votes

I am trying to build Docker image from my Dockerfile. I have Docker-CE 18.06 installed on CentOS 7 guest OS, running on VMWare Player 14. The project directory is inside shared folder mounted via VMWare's vmhgfs-fuse tool. My host OS is Windows 10 Home. As of now, I don't use docker-compose for this project yet.

[superdurszlak@localhost candidate-match]$ sudo docker build -t candidate-match .

unable to prepare context: path "." not found

[superdurszlak@localhost candidate-match]$ sudo docker build -t candidate-match --file ./Dockerfile .

unable to prepare context: path "." not found

I have double-checked if my Dockerfile is named correctly, if my docker daemon is up and running, if my working directory is correct and if shared folder's contents are accessible from inside guest OS without issues.

What are possible causes of such an error?

2

2 Answers

1
votes

This is a permission problem. If the root user does not have access to read your current directory, and you run docker commands with sudo, then you will see the "not found" error. This likely indicates that a parent directory has no read and execute permissions in the last section (e.g. chmod 700 $HOME would break root access to $HOME/my_proj).

Two solutions:

  1. As you've seen, run the commands as your own user instead of root. This is done by adding yourself to the docker group: sudo usermod -aG docker $(id -un) && newgrp docker

  2. Fix the permissions on the parent directories using chmod to be at least 0755. Make sure any sensitive files within these directories are appropriately limited (e.g. 0600).

0
votes

Apparently the solution to said problem is straightforward yet possibly not obvious to inexperienced Docker users. I needed to add my user to group docker in order to build docker image from Dockerfile placed inside shared folder.

Interestingly enough, I can now build my docker image as a user without root privileges:

[superdurszlak@localhost candidate-match]$ docker build .

Sending build context to Docker daemon 1.055MB

Step 1/8 : FROM ubuntu:18.04

works fine

But running sudo docker build ... still causes error mentioned in the question.

According to docker docs, adding user to docker group is optional, though: https://docs.docker.com/install/linux/linux-postinstall/