Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent volume creation on docker run

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?

like image 687
ronkot Avatar asked Oct 21 '25 14:10

ronkot


2 Answers

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.

like image 116
BMitch Avatar answered Oct 23 '25 05:10

BMitch


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
like image 37
Artiow Avatar answered Oct 23 '25 04:10

Artiow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!