The problem is that the base image you're using (rayproject/ray
) is configured to run as a non-root user (ray
), but sets the working directory to /
. There is a writeable directory /home/ray
available; the easiest solution is probably adding an appropriate WORKDIR
directive to your Dockerfile:
FROM rayproject/ray
WORKDIR /home/ray
ADD main.py .
CMD ["python", "main.py"]
Update
I figured this out by first spawning a shell and checking what uid the process was running as:
$ docker run -it --rm testimage bash
(base) ray@bca6b7788820:~$ id
uid=1000(ray) gid=100(users) groups=100(users),27(sudo)
I checked the passwd
file for information about that user:
(base) ray@bca6b7788820:~$ grep ray /etc/passwd
ray:x:1000:100::/home/ray:/bin/bash
And verified that directory was writeable:
(base) ray@bca6b7788820:~$ cd /home/ray
(base) ray@bca6b7788820:~$ touch foo
In general you can also figure things like this out by inspecting the corresponding Dockerfile, but for this particular base image that ended up being a bit of a pain because you need to track down a chain of dependencies:
And if you look at that last Dockerfile, you find:
USER $RAY_UID
ENV HOME=/home/ray
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…