I try to build a Jupyterhub Docker Image and cannot use chmod on the volumes.
My Dockerfile looks like this:
FROM jupyterhub/jupyterhub:latest
RUN pip install --no-cache \
oauthenticator \
dockerspawner \
jupyterhub-nativeauthenticator
COPY jupyterhub_config.py /srv/jupyterhub/jupyterhub_config.py
WORKDIR /srv/jupyterhub
VOLUME /srv/jupyterhub/shared_data
RUN chmod 777 /srv/jupyterhub/shared_data
building this leads to the following error:
> [6/6] RUN chmod 777 /srv/jupyterhub/shared_data: 0.118 chmod: cannot access '/srv/jupyterhub/shared_data': No such file or directory
Why is this and how can I fix it?
You should entirely delete that
RUNline. Also consider deleting theVOLUMEline before it.From a security point of view, changing a directory (or anything) to mode 0777 is almost never considered a best practice. It allows any user to overwrite any other user's content; "overwrite" could include subtle changes to content or injecting malware into binaries.
In the case of a Docker container, there will be only a single process inside the container, so there's no reason to use an actively insecure setup. Leave the default file mode of 0755 (writable only by the owner) and make sure the container user is correct. Since this directory will eventually be a volume mount, you can figure out what (numeric) user ID owns the host directory
and then launch the container as that specific numeric user ID.
With this volume mount, the container directory is completely replaced by the host directory, including its ownership and permission. That means that, ignoring the error, the
RUN chmodcommand still won't have an effect because a different directory will replace it. You can't make changes to the eventual mounted directory from the Dockerfile.The volume mount also doesn't require a Dockerfile
VOLUMEdirective. It's not impossible that theVOLUMEis causing the specific error you're seeing here. The most obvious effect ofVOLUMEis to prevent any further changes to the named directory in the image, so again theRUN chmodwon't have an effect; its second most obvious effect will be to leak anonymous volumes. Unless you're clear on whatVOLUMEdoes and why you want it, it's almost always safe to just delete that line.