Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing /tmp between two containers

I'm using docker-compose to spawn two containers. I would like to share the /tmp directory between these two containers (but not with the host /tmp if possible). This is because I'm uploading some files through flask to /tmp and want to process these files from celery.

flask:
    build: .
    command: "gulp"
    ports:
        - '3000:3000'
        - '5000:5000'
    links:
        - celery    
        - redis
    volumes:
        - .:/usr/src/app:rw

celery:
    build: .
    command: "celery -A web.tasks worker --autoreload --loglevel=info"
    environment:
        - C_FORCE_ROOT="true"
    links:
        - redis
        - neo4j
    volumes:
        - .:/usr/src/app:ro
like image 208
Juicy Avatar asked Sep 13 '16 13:09

Juicy


1 Answers

You can used a named volume:

flask:
    build: .
    command: "gulp"
    ports:
        - '3000:3000'
        - '5000:5000'
    links:
        - celery    
        - redis
    volumes:
        - .:/usr/src/app:rw
        - tmp:/tmp

celery:
    build: .
    command: "celery -A web.tasks worker --autoreload --loglevel=info"
    environment:
        - C_FORCE_ROOT="true"
    links:
        - redis
        - neo4j
    volumes:
        - .:/usr/src/app:ro
        - tmp:/tmp

When compose creates the volume for the first container, it will be initialized with the contents of /tmp from the image. And after that, it will be persistent until deleted with docker-compose down -v.

like image 197
BMitch Avatar answered Sep 21 '22 10:09

BMitch