Getting "docker: open .env: permission denied." when trying to pass a .env file to docker run

4.9k Views Asked by At

I have no problems running the test "Hello World" image.

But when I try to pass the --env-file variable as part of my docker run command I am getting docker: open .env: permission denied.

I have tried granting full permissions on my .env file but not joy still.

The command I am running is docker run --network host --env-file .env <IMAGE_ID>

Any help appreciated

3

There are 3 best solutions below

4
Ashok On

Step 1: Add the current user to the docker group by executing the below command

sudo usermod -aG docker $USER

Step 2: Change the permissions of docker socket which can able to connect to the docker daemon

sudo chmod 666 /var/run/docker.sock
0
adam s On

A clean reinstall of Docker fixed the problem.

1
Yiqun Liang Herman On

I have tried this all day. To solve this: I removed snap version of docker. and removed snap/bin from path export PATH=$(echo $PATH | sed 's/:/snap/bin//') and reinstall latest version of docker

make sure to run which docker to see if your docker is installed in the right folder.

For some reason snap installation of Docker can't read .envs but the apt-get installation of the "Docker Community Edition" can.