How do I mount a host directory as a volume in docker compose

前端 未结 5 1389
时光取名叫无心
时光取名叫无心 2020-12-07 08:59

I have a development environment I\'m dockerizing and I would like the ability to livereload my changes without having to rebuild docker images. I\'m using docker compose be

5条回答
  •  [愿得一人]
    2020-12-07 10:03

    we have to create your own docker volume mapped with the host directory before we mention in the docker-compose.yml as external

    1.Create volume named share

    docker volume create --driver local \
    --opt type=none \
    --opt device=/home/mukundhan/share \
    --opt o=bind share
    

    2.Use it in your docker-compose

    version: "3"
    
    volumes:
      share:
        external: true
    
    services:
      workstation:
        container_name: "workstation"
        image: "ubuntu"
        stdin_open: true
        tty: true
        volumes:
          - share:/share:consistent
          - ./source:/source:consistent
        working_dir: /source
        ipc: host
        privileged: true
        shm_size: '2gb'
      db:
        container_name: "db"
        image: "ubuntu"
        stdin_open: true
        tty: true
        volumes:
          - share:/share:consistent
        working_dir: /source
        ipc: host
    

    This way we can share the same directory with many services running in different containers

提交回复
热议问题