简体   繁体   English

永久Docker卷

[英]Persistent Docker volume

I am trying to build a Apache WebDAV private cloud server. 我正在尝试构建Apache WebDAV私有云服务器。

All my files will be in /usr/John/ directory and I can mount this location for the container to use. 我所有的文件都在/ usr / John /目录中,我可以将该位置挂载到供容器使用的位置。 The problem is that I will also add new files via this server, but whatever I try they stay only within the container. 问题在于,我还将通过该服务器添加新文件,但是无论如何,它们都只保留在容器中。 Is there a way to reflect the same new files also in the host directory (/usr/John/)? 有没有办法在主机目录(/ usr / John /)中也反映相同的新文件?

I could do a recurrent job to go into this container and CP all files to the host directory but it's not a very elegant solution. 我可以做一个经常性的工作来进入这个容器,并将所有文件CP到主机目录,但这不是一个很好的解决方案。

Use docker volumes. 使用泊坞窗卷。 All your persistent data generated by the container will be saved to var/lib/docker/volumes . 容器生成的所有持久性数据将保存到var/lib/docker/volumes If you are using docker-compise, you can do something like below. 如果您使用的是docker-compise,则可以执行以下操作。 Here I have 3 volumes and I am naming it tomcat-data , host-upload , tomcat-webapps . 在这里,我有3卷,我将其命名为tomcat-datahost-uploadtomcat-webapps Here all the data I put in tomcat-data , /home/foo/upload and /usr/local/tomcat/webapps will be stored on the host machine inside var/lib/docker/volumes . 在这里,我放入tomcat-data/home/foo/upload/usr/local/tomcat/webapps都将存储在var/lib/docker/volumes的主机上。 So even if the container goes down and you bring up another container all the data in these directories will be preserved. 因此,即使容器发生故障并启动另一个容器,这些目录中的所有数据也将保留。 Let me know if you have any questions. 如果您有任何疑问,请告诉我。

You can also bind mount host directories directly onto docker container. 您还可以将装载主机目录直接绑定到docker容器上。 Let me know if you have any questions 如果您有任何疑问,请告诉我

version: '3.2'
services:
  tomcat:
    image: "ciena/tomcat"
    volumes:
      - tomcat-data:/tomcat-data
      - host-upload:/home/foo/upload
      - tomcat-webapps:/usr/local/tomcat/webapps
    ports:
      - target: 8080
        published: 8080
        protocol: tcp
        mode: ingress
      - target: 2222
        published: 22
        protocol: tcp
        mode: ingress
    environment:
      - JAVA_MIN_HEAP=256m
      - JAVA_MAX_HEAP=512m
    deploy:
      placement:
        constraints:
          - node.role == manager
      replicas: 1
      resources:
        limits:
          memory: 1024M
          cpus: '0.5'
        reservations:
          memory: 512M
          cpus: '0.001'
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 60s
volumes:
  tomcat-data:
  host-upload:
  tomcat-webapps:
networks:
  default:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM