Dockerfile can contain VOLUME /path instruction. That means that when docker run is executed, docker creates automatically a volume and binds it to /path inside container.
I'd like to skip the automatic volume creation in some cases. Is that possible somehow?
Not once it's be added to the Dockerfile. I'd personally avoid doing volumes inside of the Dockerfile since it ends up creating anonymous volumes as you've seen, but also because it breaks attempts to modify that directory in child images or even later steps inside of the same Dockerfile.
I think it's a little late, but anyway, you can use tmpfs (if you uses Linux). It doesn't prevent mounting, but when the container stops, the tmpfs mount is removed, and files written there won't be persisted:
docker run --tmpfs /evil-dir image:tag
Intance of using tmpfs with Docker Compose:
services:
my-cool-service:
image: image:tag
tmpfs:
- /evil-dir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With