Hossein Fallah
Hossein Fallah

Reputation: 2539

Why docker compose volume creates directory by default?

Consider this dockerc-compose.yml file:

version "3.9"
services:
  site:
    image: siteimage:latest
    volumes:
       /infra:/infra
       /site:/site
       /branding/logo.png:/branding/logo.png

The point is that if logo.png does not exist in my local PC, docker creates a directory for it in the container, instead of doing nothing.

Why docker behave this way? How can I change it? How can I tell docker to either not create a directory when the local directory does not exist, or tell it to create file instead of a directory?

Note: We're creating docker-compose.yml file dynamically through a tool. Thus please don't comment you already know if logo.png exists or not. Thank you.

Upvotes: 0

Views: 2481

Answers (1)

araisch
araisch

Reputation: 1940

No, either generates it as folder or generates error: Read Docs: Differences between -v and --mount behavior

So write a bash script checking for that file and if it is a folder, remove it and write a dummy file. Then call this script from docker entrypoint and after that your real process..

Upvotes: 1

Related Questions