在docker-compose中使用docker卷而不将卷数据复制到容器

时间:2017-10-23 18:07:09

标签: docker docker-compose

我用docker-compose来容器化!我的服务。这是一个描述有问题容器的片段:

version: '2'
services:
    rabbit:
        hostname: rabbit
        image: rabbitmq:latest
        environment:
            - RABBITMQ_DEFAULT_USER=admin
            - RABBITMQ_DEFAULT_PASS=mypass
        ports:
            - "5672:5672"
        restart: unless-stopped
    redis:
        image: redis:3.2.8
        restart: unless-stopped

    worker_robot:
        image: myservice:latest
        depends_on:
            - rabbit
            - redis
        environment:
            - type_env=robot
        cap_add:
            - SYS_ADMIN
        privileged: true
        restart: unless-stopped

    service:
        image: myservice:latest
        volumes:
            - /etc/media:/app/static
            - /etc/media:/app/media
        depends_on:
            - redis
            - rabbit
        environment:
            - type_env=service
        ports:
            - "8998:8000"
        cap_add:
            - SYS_ADMIN
        privileged: true
        restart: unless-stopped

    swagger:
        image: myswagger:latest
        ports:
            - "3998:8080"
        restart: unless-stopped

/etc/media我有很多(~10 ^ 9)个文件,当我运行docker-compose up然后docker logs service_1时,我会看到类似这样的内容:

...Copying '/app/media/images/instance-image/Pic04_cyBs3du.jpg'
Copying '/app/media/images/instance-image/33c4c0.jpg'
Copying '/app/media/images/instance-image/70609.jpg'
Copying '/app/media/images/instance-image/ywic18wrgyn2tc4edr2vy6jkq13quj0oot2deogaluuow2frwclargew_2obTa5Z.jpg'
Copying '/app/media/images/instance-image/16-800x760_WtevBgc.jpg'
Copying '/app/media/images/instance-image/170404.jpg'
Copying '/app/media/images/instance-image/qd5php7wby5c1udjfbbace848oqdiqip2ebvxdv8wg1xua26iglargew.jpg'
Copying '/app/media/images/instance-image/59653.jpg'
Copying '/app/media/images/instance-image/Pic02_WN0qBss.jpg'
Copying '/app/media/images/instance-image/418a22.jpg'
Copying '/app/media/images/instance-image/vuevjnjwla3ae0l6d5nxckyajv2p2stxbkmpvmkp0xl0jeolgnlargew.jpg'
Copying '/app/media/images/instance-image/ee8e5f.jpg'
Copying '/app/media/images/instance-image/9-800x760_2R0bZJF.jpg'
Copying '/app/media/images/instance-image/180249.jpg'
Copying '/app/media/images/instance-image/lkczin6d7mtn5d8hu0qkifpokhyf1pjhov38zwkjzl06p8l8filargew.png'
Copying '/app/media/images/instance-image/d23d91.JPG'
Copying '/app/media/images/instance-image/5ab611.jpg'
Copying '/app/media/images/instance-image/a9a44c.jpg'
Copying '/app/media/images/instance-image/d02049.jpg'...
似乎docker正在将所有文件复制到某个地方。我不需要从docker容器中的这个共享文件夹中读取任何内容,只是希望容器向它们添加内容。有没有办法阻止复制这些内容?

1 个答案:

答案 0 :(得分:1)

Docker不会复制任何文件,也不会将任何日志写入服务日志。您在docker logs service_1中看到的只是myservice:latest入口点的输出(STDERR / STDOUT)。