简体   繁体   English

postgresql保留数据:更好地命名卷或绑定安装

[英]postgresql persist data: which is better named volume or bind mount

Option 1: (named container. the volume is identified by its name. It store its data in the /var/lib/docker/volumes/nameofthevolume) 选项1 :(命名容器。该卷由其名称标识。它将其数据存储在/ var / lib / docker / volumes / volumes / volumes名称中)

# create the volume in advance
  $ docker volume create test_vol

Option: 2 (here name of the volume bind-test does not matter, what matter is which local path /home/user/test it mounts to, which is persistant. Rather than /var/lib/docker/volume/somevolumename /home/user/somedatafolder makes more readability. Cons: we have to ensure that the /home/user/somedatafolder exists.) 选项:2(这里,卷bind-test名称无关紧要,重要的是它挂载到的本地路径/home/user/test ,这是持久的。而不是/var/lib/docker/volume/somevolumename /home/user/somedatafolder /var/lib/docker/volume/somevolumename /home/user/somedatafolder更具可读性。缺点:我们必须确保/home/user/somedatafolder存在。)

 # inside a docker-compose file
  ...
  volumes:
    bind-test:
      driver: local
      driver_opts:
        type: none
        o: bind
        device: /home/user/test

 or:

version: '3'
services:
myservice:
    volumes:
      - ./path:/volume/path

The downside of bind mounts is that it places files that are managed by containers, with the uid/gid from the container, inside a path likely used by other users on the host, often with a different uid/gid on the host. 绑定安装的缺点是,它将容器管理的文件以及容器中的uid / gid放置在主机上其他用户可能使用的路径内,并且主机上通常使用其他uid / gid。 The result is permission issues either on the host or inside the container. 结果是主机上或容器内的权限问题。 You need to align uid/gid's between the two to avoid this. 您需要在两者之间对齐uid / gid以避免这种情况。

At the end of the day, there isn't a big difference between bind mount and Docker named volumes. 归根结底,绑定安装和Docker命名卷之间没有太大区别。

I tend to prefer keeping persistent data from Docker services in Docker volumes. 我倾向于将来自Docker服务的持久性数据保留在Docker卷中。 You can then use tools like docker system df -v to inspect what your application uses. 然后,您可以使用诸如docker system df -v类的工具来检查应用程序使用的内容。

As for exporting the data, you can use docker cp 至于导出数据,可以使用docker cp

docker cp someContainer:/somedir/ .

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

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