Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add bind mount to Dockerfile just like volume

I want to add the bind mount to docker file just like I initialise a volume inside Dockefile. Is there any way for it?

like image 593
Mufeed Avatar asked Dec 22 '17 13:12

Mufeed


People also ask

Is bind mount a volume?

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 in a Dockerfile?

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 .

What is the difference between volumes and bind mounts?

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.


1 Answers

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

like image 174
boyvinall Avatar answered Oct 20 '22 00:10

boyvinall