docker run --env-file /path/to/file.env fails with "no such file or directory"

852 Views Asked by At

I'm trying to run a docker image on a Debian server. The preproduced image has been pulled from Docker Hub.

The cmd line is (stripped to the bones):

sudo docker run -d -p 8190:433 --env-file /path/to/file.env my-image

/path/to/file.env is similiar to /var/lib/myapp/data/file.env

Executing this results in an error message:

docker: open /path/to/file.env: no such file or directory

But: the file exists (ls /path/to/file.env shows the file). Tried also chown to root and chmod 777 wthout success. Tried also copying the file to /tmp and referring to this file.

1

There are 1 best solutions below

2
Jirapong On

Let me copy comment from derpirscher here.

By any chance you installed docker via snap? If yes, it can't access any files outside of $HOME directory (see snapcraft.io/install/docker/debian)

say if you move file to

/root/snap/file.env

then run

sudo docker run -d -p 8190:433 --env-file /root/snap/file.env my-image