Sharing /tmp between two containers

半世苍凉 提交于 2021-01-27 04:42:46

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/39471631/sharing-tmp-between-two-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!