Home  >  Q&A  >  body text

golang - docker volume挂载不存在的主机目录到容器时,自动创建的目录的权限为root

请问,我用docker volume时,挂在本地目录到容器目录。如果本地目录不存在,docker会自动创建一个。比如:
docker run --name=node-1 --rm=true --volume=/home/simba/work/test:/home/jovyan/work --publish=:8888 --publish-all=false jupyter/all-spark-notebook
当test用户不存在时,docker会自动创建test.然而自动创建的test的权限是drwxr-xr-x 2 root root, 在容器中没有权限在该目录下新建文件。请问如何解决这个问题?

伊谢尔伦伊谢尔伦2709 days ago674

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-22 09:00:56

    In the situation you mentioned, Docker’s data volume should be used. In Swarm, you should not use the method of mounting the host directory to save data.

    Create the required data volume in the Swarm environment, and then the container can use the data volume. Can use docker volume create mydata 来创建数据卷,然后在挂载时使用 -v mydata:/opt/data,或者直接在 docker-composevolumes: partial definition:

    volumes:
        mydata:{}

    can solve the problem you mentioned.

    reply
    0
  • Cancelreply