Docker撰写不持久化数据 [英] Docker compose not persisting data
问题描述
我有以下 docker-compose.yml
文件:
version: '2'
services:
web:
image: myspringapp:1
ports:
- "8080:8080"
depends_on:
- myspringapp_postgres
myspringapp_postgres:
image: postgres:9.4
ports:
- "5432:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data
volumes:
pgdata: {}
myspringapp是我之前构建的docker映像。问题是执行 docker-compose stop
后数据丢失。有人知道问题出在哪里吗?
myspringapp is a docker image I build previously. The problem with this is that the data is lost after doing a docker-compose stop
. Anyone know what the problem is?
推荐答案
好像在定义一个卷,但是指定了要使用的绑定挂载
Looks like you're defining a volume, but specifying a bind-mount to be used.
在某种意义上,卷实际上是它自己的独立驱动器,其中绑定安装需要映射到您的特定文件路径
The different here, is a volume is actually it's own isolated "drive" in a sense, where a bind-mount needs to map to a specific file path on your local system.
如果您在本地 ./ pgdata
目录中签入,则应该找到以前的所有数据。并且要解决您的问题,您需要从其中删除 ./
,并仅指定名称 pgdata
,以便它使用定义的卷。当然,这会重新开始。
If you check in your local ./pgdata
directory, you should find all your previous data; and to fix your issue you'll want to remove the ./
from that and just specify the name pgdata
so that it uses the volume as defined. Of course, this will start you fresh again.
compose-file.yml
version: '2'
services:
web:
image: myspringapp:1
ports:
- "8080:8080"
depends_on:
- myspringapp_postgres
myspringapp_postgres:
image: postgres:9.4
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata: {}
这篇关于Docker撰写不持久化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!