[英]Docker volume data does not get saved to host folder in mac
Here is my docker compose file 这是我的docker撰写文件
version "2"
services:
my_postgres:
image: postgres:9.6
volumes:
- /Users/my_user_name/test_docker/my_volume_space:/var/lib/postgresql
ports:
- "5432:5432"
I entered the following command in mac 我在Mac中输入了以下命令
docker-machine start
docker-machine env
evcal "$(docker-machine env default)"
docker-compose up
psql -h 192.168.99.100 -p 5432 -U postgres
create table test (my_id bigserial primary key);
INSERT INTO test (my_id) values (1);
SELECT * FROM test;
\q
Originally I thought the above commands will cause a .sql
file to be created in ./my_volume_space
of the host computer. 最初,我认为上述命令将导致在主机的./my_volume_space
中创建一个.sql
文件。 But I don't see any .sql
file in ./my_volume_space
rather just an empty data
directory in ./my_volume_space
但我看不出有任何.sql
文件./my_volume_space
而只是一个空data
目录./my_volume_space
Furthermore if I docker-compose down
and docker-compose up
again I can see my data in the database is now gone. 此外,如果我再次进行docker-compose down
和docker-compose up
我可以看到数据库中的数据现在消失了。
I suspected that when I created the data when the image is running, the data is not stored back to ./my_volume_space
thus when I reboot, there is nothing to mount from the host. 我怀疑在运行映像时创建数据时,数据不会存储回./my_volume_space
因此当我重新启动时,没有任何内容可以从主机上挂载。
Can someone tell me what I am doing wrong? 有人可以告诉我我在做什么错吗?
Thanks 谢谢
我相信容器上的卷路径是/var/lib/postgresql/data
而不是/var/lib/postgresql
Path volumes do not work on docker-machine (macOS) with postgres image, source . 路径卷在具有postgres映像source的 docker-machine(macOS)上不起作用。
The work-around is to use named volumes. 解决方法是使用命名卷。 Example docker-compose.yaml: 示例docker-compose.yaml:
services:
test-postgres-compose :
...
volumes :
- pgdata:/var/lib/postgresql/data
...
volumes :
pgdata :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.