volumes_from instruction - docker compose

后端 未结 2 1735
無奈伤痛
無奈伤痛 2021-01-15 00:08

With the below docker-compose.yml file:

test:
  build: ../../
  dockerfile: docker/dev/Dockerfile
  volumes_from:
    - cachev

cachev:
  build:         


        
2条回答
  •  再見小時候
    2021-01-15 00:52

    Yes, you can verify by executing a command inside both containers. if creat file in test container under touch /build/fromtest.txt path, it will be visible in cacheV container on the same path /build/fromtest.txt.

    volumes_from

    Mount all of the volumes from another service or container

    compose-file-volumes_from

    A demo you can try

    test:
      image: alpine
      command: sh -c "touch /build/fromtest.txt && echo hell from test-container && ls /build/"
      volumes_from:
        - cachev
    
    cachev:
      image: node:alpine
      command: sh -c "touch /build/fromcache.txt && echo hello from cache-container && ls /build/"
      volumes:
        - /build
    

    log will be

    Recreating compose-volume_cachev_1 ... done
    Recreating compose-volume_test_1   ... done
    Attaching to compose-volume_cachev_1, compose-volume_test_1
    cachev_1  | hello from cache-container
    test_1    | hell from test-container
    test_1    | fromcache.txt
    test_1    | fromtest.txt
    cachev_1  | fromcache.txt
    cachev_1  | fromtest.txt
    

提交回复
热议问题