aio-libs / aiodocker

Python Docker API client based on asyncio and aiohttp
Other
429 stars 97 forks source link

Asynchronous running of an image (Documentation) #267

Closed nazariyv closed 5 years ago

nazariyv commented 5 years ago

Can you add the following case to examples? I just cannot figure out how to do this from the docs/sources (and all the communication channels: SO/Gitter/Google are silent). And this is a very simple case. I have an image tagged 'wgettor:latest', it wgets the urls for me. I bind the /workdir/ in the container with my external path. This container downloads a single URL, so it's existence is just download the URL and poof it is gone. The code with docker is like this:

import docker

def synchronous_request(url):
    client = docker.from_env()

    local_dir = '/home/ubuntu/git/docker-scraper/data'
    volumes = {local_dir: {'bind': '/download/', 'mode': 'rw'}}
    environment = {'URL': url}

    client.containers.run('wgettor:latest', auto_remove=True, volumes=volumes, environment=environment)

I want to make it asynchronous with your library. Clearly the below does not work, because config is used for CMDs (from what I have seen in the docs):

import aiodocker

async def make_historical_request(url):

    docker = await aiodocker.Docker()
    client = await aiodocker.DockerContainers(docker)

    local_dir = '/home/ubuntu/git/docker-scraper/data'
    volumes = {local_dir: {'bind': '/download/', 'mode': 'rw'}}
    environment = {'URL': url}

    await client.run(config={"auto_remove": "True",
                             "volumes": volumes,
                             "environment": environment}, name="wgettor:latest")
aio-libs-bot commented 5 years ago

Hi, I'm GitMate.io!

It seems you've just enabled the issue triaging. I'm just scraping all issues from your repository and will give you some more information about this in a few minutes or so.

Because of the rate limit we can't scrape all information (including all comments and authors) right now - our system is already set up to scrape this in the next days over which the predictions will become more precise every day.

If you want me to use a different account for triaging your issues, simply create one and log in with it.

Sit tight!

aio-libs-bot commented 5 years ago

GitMate.io thinks possibly related issues are https://github.com/aio-libs/aiodocker/issues/33 (Support building images), and https://github.com/aio-libs/aiodocker/issues/239 (how to build an image with aiodocker).

nazariyv commented 5 years ago

So the most useful thing for me is probably here: https://github.com/aio-libs/aiodocker/blob/master/tests/test_containers.py, where it shows how to run the container. But it does not show, how to bind the workdir to local path.

nazariyv commented 5 years ago

Figured it out. But now have tons of warnings for unclosed session from aiohttp...

nazariyv commented 5 years ago

because I wasn't closing docker.. all sorted.