Docker 卷按字母顺序运行,而不是我放置它们的顺序
我有一个看起来像这样的 docker-compose.yml 文件,
version: '3.7'
services:
postgres:
image: postgres:12.7
restart: always
environment:
- POSTGRES_USER=xxxx
- POSTGRES_PASSWORD=xxxx
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5438:5432'
volumes:
- ./A.sql:/docker-entrypoint-initdb.d/A.sql
- ./B.sql:/docker-entrypoint-initdb.d/B.sql
- ./D.sql:/docker-entrypoint-initdb.d/D.sql
- ./C.sql:/docker-entrypoint-initdb.d/C.sql
我将卷中的文件这样放置,以便首先运行 A,第二运行 B,第三运行 D,最后运行 C。但是,当我运行 docker-compose up 时,它按字母顺序运行文件,而不是我放置它们的顺序。有没有解决这个问题的方法?
I have a docker-compose.yml file that looks like this
version: '3.7'
services:
postgres:
image: postgres:12.7
restart: always
environment:
- POSTGRES_USER=xxxx
- POSTGRES_PASSWORD=xxxx
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5438:5432'
volumes:
- ./A.sql:/docker-entrypoint-initdb.d/A.sql
- ./B.sql:/docker-entrypoint-initdb.d/B.sql
- ./D.sql:/docker-entrypoint-initdb.d/D.sql
- ./C.sql:/docker-entrypoint-initdb.d/C.sql
I have the files in the Volumes placed like this so that A will be run first, B second, D third, and C last. However, when I run docker-compose up, it's running the files in alphabetical order as opposed to the order I placed them in. Is there anyway around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以映射文件,以便它们在容器内具有名称,从而使它们按照您想要的顺序执行。像这样
You can map the files, so they have names inside the container that'll cause them to be executed in the order you want. Like this
docker postgres 镜像按字母顺序运行初始化脚本:
来源。
如果您想更改顺序,则必须更改文件的名称。它们安装到容器中的顺序将被忽略。
The docker postgres image runs the initialization scripts in alphabetical order:
Source.
If you wish to change the order, you must change the names of the files. The order that they are mounted into the container is ignored.