Low Orbit Flux Logo 2 F

Docker How To Bind Mount Local Directory

If you are looking for instructions on how to bind mount with Docker you have come to the right place. Fortunately this is easy.

You can bind mount a directory like this:


docker run -tid --name test3 -v /src/data:/data ubuntu    

You can make it read only like this


docker run -tid --name test4 -v /src/data:/data:ro ubuntu  # RO

Apparently, you can’t setup a bind mount in a Dockerfile but you can do it using Docker compose like this:



user1@host1:~$ cat docker-compose.yaml
services:
  one:
    image: nginx
    container_name: test3
  two:
    image: ubuntu
    container_name: test4
    stdin_open: true
    tty: true
    volumes:
      - '/home/user1/data:/data'