How to create docker volume device/host path

前端 未结 3 1370
庸人自扰
庸人自扰 2020-12-31 23:12

I believe there is an easy way to copy files into a docker volume that has already been mounted to a container.

docker cp /tmp/my_data/. my_container:/my_data

3条回答
  •  我在风中等你
    2020-12-31 23:31

    To bind volumes between container and host machine. The most easy way is to use volume mounting. With which we can setup your container before starting it, (its images, ports, ..etc)

    To build the container from an image: docker-compose build To start the container : docker-compose up

    Volumes key in the docker-compose file is used to set the binding. which means when we update the content of volumes in the container it will persist even after stopping the container.

    We can bind volumes from a local dir or from a named docker volume see the exmple below

    We can use COPY or ADD in your Dockerfile to make the content of your local diroctory available in the docker container.

    read docs here

    version: "3.2"
    services:
      web:
        image: nginx:alpine
        ports:
          - "80:80"
        volumes:
          - type: volume
            source: mydata
            target: /data
            volume:
              nocopy: true
          - type: bind
            source: ./static
            target: /opt/app/static
    
        networks:
          webnet:
    
        volumes:
    

提交回复
热议问题