compose icon indicating copy to clipboard operation
compose copied to clipboard

docker-compose v2 incompatible volume handling

Open everflux opened this issue 2 years ago • 2 comments

Description In docker-compose 1.29 I could mount an empty directory and get the initial content from the overlay FS if the directory was empty (just like with a regular docker -v). This no longer works with docker-compose v2

Steps to reproduce the issue:

  1. docker-compose up
  2. ls -lR

Describe the results you received: Empty directories

Describe the results you expected: Directories with the initial content of the overlayfs

Additional information you deem important (e.g. issue happens only occasionally):

config example

version: "3"

services:
  app:
    image: sample
    volumes:
      - config:/var/www/html/config

volumes:
  config:
    driver_opts:
        type: none
        device: ${PWD}/config
        o: bind

everflux avatar Feb 27 '22 13:02 everflux

I'm not sure why/how this behavior exists with docker-compose v1, but that sounds weird to me an explicit bind mount does not override the image content. I can understand the benefit for volume to be created with initial content from image. This is the case if your Dockerfile declares a VOLUME and your service configuration does not set an explicit mount for it ("anonymous volumes"), but I didn't know compose v1 allowed to do so with an explicit volume. I guess the main difference is the use of the mount API in compose v2, while compose v1 uses the legacy bind API everywhere.

ndeloof avatar Feb 28 '22 09:02 ndeloof

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '22 10:09 stale[bot]