question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New syntax to mount Docker volumes with --mount

See original GitHub issue

I had this after reading #12537 and #9047. Currently DockerOperator’s volumes argument is passed directly to docker-py’s bind (aka docker -v). But -v’s behaviour has long been problematic, and Docker has been pushing users to the new --mount syntax instead. With #12537, it seems like -v’s behaviour is also confusing to some Airflow users, so I want to migrate Airflow’s internals to --mount.

However, --mount has a different syntax to -v, and the behaviour is also slightly different, so for compatibility reasons we can’t just do it under the hood. I can think of two possible solutions to this:

A. Deprecate volumes altogether and introduce DockerOperator(mounts=...)

This will emit a deprecation warning when the user passes DockerOperator(volumes=...) to tell them to convert to DockerOperator(mounts=...) instead. volumes will stay unchanged otherwise, and continue to be passed to bind mounts.

mounts will take a list of docker.types.Mount to describe the mounts. They will be passed directly to the mounts API. Some shorthands could be useful as well, for example:

DockerOperator(
    ...
    mounts=[
        ('/root/data1', './data1'),  # Source and target, default to volume mount.
        ('/root/data2', './data2', 'bind'),  # Bind mount.
    ],
)

B. Reuse volumes and do introspection to choose between binds and mounts

The volumes argument can be augmented to also accept docker.types.Mount instances, and internally we’ll do something like

binds = []
mounts = []
for vol in volumes:
    if isinstance(vol, str):
        binds.append(vol)
    elif isintance(vol, docker.types.Mount):
        mounts.append(vol)
    else:
        raise ValueError('...')
if binds:
    warnings.warn('...', DeprecationWarning)

and pass the collected lists to binds and mounts respectively.

I’m very interested in hearing thoughts on this.

Are you willing to submit a PR? Yes

Related Issues

  • #12537: Confusing on the bind syntax.
  • #9047: Implement mounting in DockerSwarmOperator (it’s a subclass of DockerOperator, but the volumes option is currently unused).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
uranusjrcommented, May 14, 2021

In that case I think I’ll go with Option A, but removing volumes instead of deprecating.

1reaction
uranusjrcommented, May 14, 2021

PR created 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Volumes - Docker Documentation
--mount : Consists of multiple key-value pairs, separated by commas and each consisting of a <key>=<value> tuple. The --mount syntax is more verbose...
Read more >
Docker Mount Volume – How To Mount a Local Directory
Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to...
Read more >
Mounting a Volume Inside Docker Container - GeeksforGeeks
Docker allows you to mount shared volumes in multiple Containers. ... To create a new Docker Volume, you can use the Volume Create...
Read more >
Guide to Docker Volumes - Baeldung
A bind mount uses the host file system, but Docker volumes are native to Docker. The data is kept somewhere on storage attached...
Read more >
Docker Volumes: How to Create & Get Started - phoenixNAP
To mount a data volume to a container add the --mount flag to the docker run command. It adds the volume to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found