[英]Locally mount AWS EFS using docker-compose
我想知道是否有一种简单的方法可以使用 Amazon EFS(弹性文件系统)在本地 docker-compose 设置中作为卷安装。
原因是对于本地开发,创建的卷会保留在我的笔记本电脑上 - 如果我要更换机器,我将无法访问任何底层数据。 云 NFS 可以解决这个问题,因为它可以从任何地方随时可用。
AWS 文档( https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html )似乎建议使用 AWS Direct Connect / VPN - 有没有办法通过打开端口来避免这种情况2049(NFS 流量)在侦听所有 IP 地址的安全组中,并将该安全组应用于新创建的 EFS?
这是我的 docker-compose.yml:
version: "3.2"
services:
postgres_db:
container_name: "postgres"
image: "postgres:13"
ports:
- 5432:5432
volumes:
- type: volume
source: postgres_data
target: /var/lib/postgresql/data
volume:
nocopy: true
environment:
POSTGRES_USER: 'admin'
POSTGRES_PASSWORD: "password"
volumes:
postgres_data:
driver_opts:
type: "nfs"
o: "addr=xxx.xx.xx.xx,nolock,soft,rw"
device: ":/docker/example"
我收到以下错误:
ERROR: for postgres_db Cannot start service postgres_db: error while mounting volume '/var/lib/docker/volumes/flowstate_example/_data': failed to mount local volume: mount :/docker/example:/var/lib/docker/volumes/flowstate_example/_data, data: addr=xxx.xx.xx.xx,nolock,soft: connection refused
我认为我的笔记本电脑连接不是 AWS EFS VPC 的一部分,因此无法挂载 EFS。
对于添加的上下文,我希望将网络抓取设置 dockerize 并将数据量保存在云中,以便我可以从任何地方连接到它。
EFS 假设 nfs4,所以:
version: '3.8'
services:
postgres:
volumes:
postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
driver_opts:
type: "nfs4"
o: "addr=xxx.xx.xx.xx,nolock,soft,rw"
device: ":/docker/postgres_data"
当然,引用的 nfs-export/path 必须存在。 Swarm 不会自动创建不存在的文件夹。
在重新创建堆栈之前,请确保手动删除任何这种错误类型/名称的旧 docker 卷(在所有 swarm 节点上!):
docker volume rm $(docker volume ls -f name=postgres_data -q)
理解这一点很重要:Docker NFS 卷实际上只是声明在哪里可以找到数据。 当您更新 docker-compose.yml 时它不会更新,因此您必须删除该卷,以便出现任何新配置
见输出
docker service ps stack_postgres --no-trunc
有关为什么无法安装卷的更多信息
还要确保您可以通过mount -t nfs4 ...
挂载 nfs-export
请参阅showmount -e your.efs.ip.address
volumes:
nginx_test_vol:
driver_opts:
type: "nfs"
o: "addr=fs-xxxxxxxxxxxxxxxxxx.efs.us-east-1.amazonaws.com,rw,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport"
device: ":/nginx-test"
这让我很好地使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.