How do I share a docker-compose volume with a linux host?

1.8k views Asked by At

I have a docker-compose.yml

version: '3.3'

services:
    ssh:
        environment:
          - TZ=Etc/UTC
          - DEBIAN_FRONTEND=noninterative
        build:
            context: './'
            dockerfile: Dockerfile
        ports:
            - '172.17.0.2:22:22'
            - '443:443'
            - '8025:8025'
        volumes:
            - srv:/srv:rw
        restart: always
volumes:
  srv:

After I run docker-compose up --build I can ssh to the docker vm and there are files in /srv. 'docker volume ls' shows 2 volumes, srv and dockersetupsrv. They are both in /var/lib/docker/volumes. They both contain _data directories and show creation time stamps that match the docker image creation times but are otherwise empty. Neither one contains any of the files that are in the docker container's /srv directory. How can I share the docker /srv directory with the host?

1

There are 1 answers

0
Long On

you should point out more specific for the mapping directory, for example:

  • /srv:/usr/srv:rw after that, when you add content inside your host machine /srv,it is automatically map into /usr/srv --> make sure that directory exist

you can have a check in this link : https://docs.docker.com/storage/volumes/