Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 590
adam s Avatar asked Sep 07 '25 00:09

adam s


1 Answers

To solve this, I removed the snap version of docker using sudo snap remove docker and re-installed the latest version with apt using sudo apt install docker. Optionally, you can also remove snap's bin from PATH export PATH=$(echo $PATH | sed 's/:\/snap\/bin//')

Make sure to run which docker to see if your docker is installed in the right folder - for me it was in /usr/bin.

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

like image 192
Yiqun Liang Herman Avatar answered Sep 10 '25 04:09

Yiqun Liang Herman