'Facing the following error while trying to create a Docker Container using a DockerFile -> "error from sender: open .Trash: operation not permitted"

Im completely new to Docker and I'm trying to create and run a very simple example using instructions defined in a DockerFile.

DockerFile->

FROM ubuntu:latest

RUN apt-get update 

RUN apt-get install -y python3 pip

COPY ./ .

RUN python3 test.py

contents of test.py ->

import pandas as pd

import numpy as np

print('test code')

command being used to create a Docker Container ->

docker build --no-cache . -t intro_to_docker -f abs/path/to/DockerFile

folder structure -> (both files are present at abs/path/to)

abs/path/to:

    -DockerFile

    -test.py

Error message ->

error from sender: open .Trash: operation not permitted

(using sudo su did not resolve the issue, which i believe is linked to the copy commands)

I'm using a Mac.

any help in solving this will be much appreciated!



Solution 1:[1]

The Dockerfile should be inside a folder. Navigate to that folder and then run docker build command. I was also facing the same issue but got resovled when moved the docker file inside a folder

Solution 2:[2]

Usually the error would look like:

error: failed to solve: failed to read dockerfile: error from sender: open .Trash: operation not permitted

And in my case, it's clearly saying that it is unable to find the dockerfile.

Also, in your command, I see a . after --no-cache, I think that's not required?

So better, try navigating to the specified path and then run the build command replacing the -f option with a ., which specifies the build command to consider the current folder for its build process.

In your case

cd abs/path/to/
docker build --no-cache -t intro_to_docker .

Solution 3:[3]

It seems the system policies are not allowing the application to execute this command. The application "Terminal" might not have approval to access the entire file system.

Enable full disk access to terminal. Change it using "System Preferences > Security & Privacy > Privacy > Full Disk Access"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shikhar Chaudhary
Solution 2 Goutham
Solution 3 Praveen Vattikuti