Add bind mount to Dockerfile just like volume

Mufeed picture Mufeed · Dec 22, 2017 · Viewed 24.2k times · Source

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

Answer

boyvinall picture boyvinall · Dec 22, 2017

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