docker / docker/docker-py

Best Practice: Read Only Mounts in Swarm

Open
#2,813 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

Current Setup

Right now, my current setup looks something like this,

driver = DriverConfig(
    name=None,
    options={
        "o": "nfsvers=4.0,noatime,nodiratime,soft,addr=x.x.x.x,ro", #read-only
        "device": ":/path/to/data",
        "type": "nfs",
       },
)
mount = Mount(
    type="volume",
    source=None,
    target="/data",
    driver_config=driver,
)
container = ContainerSpec(
    image=image_name,
    command=command,
    args=arguments,
    env=environment,
    mounts=[mount]
    ...
)
task = TaskTemplate(
    container_spec=container,
    restart_policy=RestartPolicy("none"),
    placement=placement,
    resources=resources,
    ...
)
service = client.create_service(
    task,
    name=name,
    networks=["swarm-attachable-network"] ,
    endpoint_spec=EndpointSpec(mode="vip"),
)

Question

Alternatively, there is also an option to specify a mount to be read-only via,

mount = Mount(
    type="volume",
    source=None,
    target="/data",
    driver_config=driver,
    read_only=True, # read-only
    ...
)

This fails however with the following error,

"invalid mount config for type "volume": must not set readonly mode when using anonymous volumes"

In this scenario what is the best practice to deploy NFS mounts?

  • Can source be any uuid identifier?
  • Does source have to be a pre-defined volume?
  • Do you have to make host specific volume on each swarm node?
  • Can you centrally manage volumes?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files or tests are named. Start by reviewing the Mount, DriverConfig, ContainerSpec, and Docker Swarm volume behavior involved in the example, then verify the supported NFS deployment patterns. Done means documenting whether source identifiers, predefined volumes, host-specific volumes, and centralized volume management are supported, including the read-only limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops, infrastructure
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.