When docker volume mounts a nonexistent host directory to the container, the permission of the automatically created directory is root

  golang, question

Excuse me, when I use docker volume, I hang it from the local directory to the container directory. If the local directory does not exist, docker automatically creates one. For example:
docker run –name=node-1 –rm=true –volume=/home/simba/work/test:/home/jovyan/work –publish=:8888 –publish-all=false jupyter/all-spark-notebook
When the test user does not exist, docker will automatically create the test. However, the permission for the automatically created test is drwxr-xr-x2root, and there is no permission in the container to create a new file in this directory. How to solve this problem?

The situation you mentioned should use Docker’s data volume. In Swarm, data should not be saved by mounting the host directory.

Create the required data volume in the Swarm environment, and then the container can use the data volume. Can be useddocker volume create mydataTo create a data volume and then use it at mount time-v mydata:/opt/data, or directly in thedocker-composeThevolumes:Some definitions:

volumes:
 mydata:{}

Can solve the problem you said.