Docker-compose mariadb 外部卷映射问题 [英] Docker-compose mariadb external volume mapping issue
问题描述
我想使用外部目录作为音量和挣扎
I wanted to use external directory as volume and struggling
mariadb:
image: mariadb:10.4
...
environment:
..
logging:
...
networks:
- backend
restart: on-failure
volumes:
- maria_volume:/var/lib/mysql
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
# Volumes
volumes:
maria_volume:
maria_volume: 是什么意思?
参考:https://www.cloudytuts.com/tutorials/docker/how-to-add-persistent-data-to-mysql-with-docker-compose/
理想情况下我想要类似的东西
Ideally I want something like
volumes:
maria_volume:
external:
name: ${PWD}/mariadb
但它给出了错误
卷 C:/some/test/mariadb 声明为外部,但不能成立.请使用 docker volume create --name=C:/some/test/mariadb
手动创建卷,然后重试.
Volume C:/some/test/mariadb declared as external, but could not be found. Please create the volume manually using
docker volume create --name=C:/some/test/mariadb
and try again.
如果我运行卷创建,它会报错
If I run the volume create, it complains
仅包含本地卷名的无效字符[a-zA-Z0-9][a-zA-Z0-9_.-]"
includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]"
如何创建外部卷并查看数据文件?
How can I create external volume and see data files?
我的环境是带有 Gitbash 的 Windows10.但我正在寻找一种适用于任何地方的解决方案,即我的本地 + 云
My environment is Windows10 with Gitbash. But I am looking for a solution that works anywhere i.e. my local + cloud
推荐答案
在你展示的这个文件中,maria_volume
是一个 命名卷.您可能想要一个 绑定挂载 代替:删除 volumes:
块在文件末尾,并在容器设置中,使用主机目录名称而不是名称 maria_volume
.
In this file as you've shown it, maria_volume
is a named volume. You probably want a bind mount instead: remove the volumes:
block at the end of the file, and in the container setup, use the host directory name instead of the name maria_volume
.
version: '3.8'
services:
mariadb:
volumes:
# Compose knows how to interpret relative paths;
# they are relative to the location of the docker-compose.yml file
- ./mariadb:/var/lib/mysql
# no top-level volumes: for this setup
请注意,在某些平台上,Docker 命名卷可能比绑定挂载快得多.由于数据库存储将是复杂二进制格式的不透明文件,因此您无法真正直接查看它们,即使您确实拥有 Docker 空间之外的文件.问题中的命名卷方法实际上可能更适合数据库存储.
Note that, on some platforms, Docker named volumes may be significantly faster than bind mounts. Since the database storage will be opaque files in a complex binary format, you can't really look at them directly, even if you do have the files outside of Docker space. The named-volume approach in the question may actually be better for database storage.
这篇关于Docker-compose mariadb 外部卷映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!