I want to add the bind mount to docker file just like I initialise a volume inside Dockefile. Is there any way for it?
Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.
Can You Mount a Volume While Building Your Docker Image to Cache Dependencies? Right now, you can't mount volumes, as you can when working with containers. There is no -v option when issuing a docker build .
Getting started using bind mounts The most notable difference between the two options is that --mount is more verbose and explicit, whereas -v is more of a shorthand for --mount . It combines all the options you pass to --mount into one field.
A Dockerfile defines how an image is built, not how it's used - so you can't specify the bind mount in a Dockerfile. Try using docker-compose instead. A simple docker-compose.yml
that mounts a directory for you would look like this:
version: '3.1' services: mycontainer: image: myimage build: . volumes: - './path/on/docker/host:/path/inside/container'
The build: .
is optional if you're building the image by some other means, but sometimes it's handy to do it all in one.
Run this with docker-compose up -d
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