持久性Docker卷 [英] Persistent Docker volume

查看:74
本文介绍了持久性Docker卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建Apache WebDAV私有云服务器.

I am trying to build a Apache WebDAV private cloud server.

我所有的文件都在/usr/John/目录中,我可以将该位置挂载到供容器使用的位置.问题在于,我还将通过该服务器添加新文件,但是无论如何,它们只会保留在容器中.有没有办法在主机目录(/usr/John/)中也反映相同的新文件?

All my files will be in /usr/John/ directory and I can mount this location for the container to use. 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/)?

我可以经常性地进入这个容器并将所有文件CP到主机目录,但这不是一个很好的解决方案.

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.

推荐答案

使用docker卷.容器生成的所有持久性数据将保存到 var/lib/docker/volumes 中.如果您使用的是docker-compise,则可以执行以下操作.在这里,我有3卷,我将其命名为 tomcat-data host-upload tomcat-webapps .在这里,我放入 tomcat-data /home/foo/upload /usr/local/tomcat/webapps 中的所有数据都将被存储在 var/lib/docker/volumes 内的主机上.因此,即使容器发生故障并启动另一个容器,这些目录中的所有数据也将保留.如果您有任何疑问,请告诉我.

Use docker volumes. All your persistent data generated by the container will be saved to var/lib/docker/volumes. If you are using docker-compise, you can do something like below. Here I have 3 volumes and I am naming it tomcat-data, host-upload, tomcat-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. 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.

您还可以将装载主机目录直接绑定到docker容器上.让我知道您是否有任何疑问

You can also bind mount host directories directly onto docker container. 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:

这篇关于持久性Docker卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆