在两个容器之间共享/tmp [英] Sharing /tmp between two containers

查看:56
本文介绍了在两个容器之间共享/tmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 docker-compose 生成两个容器.我想在这两个容器之间共享/tmp 目录(如果可能,不要与主机/tmp 共享).这是因为我要通过 flask 将某些文件上传到/tmp ,并希望从 celery 处理这些文件.

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

推荐答案

您可以使用命名卷:

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

当compose为第一个容器创建卷时,将使用映像中/tmp的内容对其进行初始化.然后,它会一直保留,直到使用 docker-compose down -v 删除.

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.

这篇关于在两个容器之间共享/tmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆