Docker, mount volumes as readonly

前端 未结 2 532
轮回少年
轮回少年 2021-01-30 01:46

I am working with Docker, and I want to mount a dynamic folder that changes a lot (so I would not have to make a Docker image for each execution, which would be too costly), but

2条回答
  •  -上瘾入骨i
    2021-01-30 02:46

    You can specify that a volume should be read-only by appending :ro to the -v switch:

    docker run -v volume-name:/path/in/container:ro my/image
    

    Note that the folder is then read-only in the container and read-write on the host.

    2018 Edit

    According to the Use volumes documentation, there is now another way to mount volumes by using the --mount switch. Here is how to utilize that with read-only:

    $ docker run --mount source=volume-name,destination=/path/in/container,readonly my/image
    

    docker-compose

    Here is an example on how to specify read-only containers in docker-compose:

    version: "3"
    services:
      redis:
        image: redis:alpine
        read_only: true
    

提交回复
热议问题