Add bind mount to Dockerfile just like volume

后端 未结 3 1928
青春惊慌失措
青春惊慌失措 2021-02-01 04:38

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

3条回答
  •  野的像风
    2021-02-01 05:11

    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

提交回复
热议问题