gpt4 book ai didi

docker-compose 名为 : "prefix_%s_1" instead of "%s" 的图像

转载 作者:IT老高 更新时间:2023-10-28 12:40:07 25 4
gpt4 key购买 nike

当我在带有链接的 docker-compose.yaml 文件中设置几个 Docker 容器时,容器的名称最终采用 prefix_%s_1 格式而不是%s,和链接容器上/etc/hosts中的别名是一样的。

为什么redis容器的别名是test_redis_1而不是redis

以下是相关文件和输出:

# docker-compose.yaml
monkey:
build: ../../monkey
dockerfile: test.Dockerfile
links:
- redis:redis
ports:
- "9006:9006"

redis:
build: ../storage/redis
ports:
- "6379:6379"

运行后docker-compose build && docker-compose up:

$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
test_redis_1 redis-server /usr/local/et ... Up 0.0.0.0:6379->6379/tcp
test_monkey_1 python -m SimpleHTTPServer ... Up 0.0.0.0:9006->9006/tcp

test_monkey_1 容器的输出:

Step 14 : RUN cat /etc/hosts
---> Running in 1c104e3d9bf5
172.17.1.26 75a485df1325
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.1.26 thirsty_lumiere.bridge
172.17.0.220 test_redis_1
172.17.0.220 test_redis_1.bridge
172.17.1.26 thirsty_lumiere
---> 3a06bac9b3ca
Removing intermediate container 1c104e3d9bf5
Step 15 : RUN echo
---> Running in a1c5b5f8ae0f

---> 385c9ee44332
Removing intermediate container a1c5b5f8ae0f
Step 16 : RUN ifconfig eth0 | grep inet addr
---> Running in 17cd638c6473
inet addr:172.17.1.28 Bcast:0.0.0.0 Mask:255.255.0.0
---> 21235e29abc1
Removing intermediate container 17cd638c6473
Step 17 : RUN echo
---> Running in 8c0b1db2a69b

---> e2dd190eb4d1
Removing intermediate container 8c0b1db2a69b
Step 18 : RUN env
---> Running in 50cd1b6bf9da
HOSTNAME=75a485df1325
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/data/web/tunnelbear.com/play/tPWD=/data/web/tunnelbear.com/root
_=/usr/bin/env

最佳答案

根据docker compose issue #745 :

By default, Compose bases the project name on basename of the directory compose commands are run from. The project name can be overridden either by passing a -p / --project-name option for each command or setting the COMPOSE_PROJECT_NAME environment variable.

您可以通过编写如下内容将您选择的前缀设置为容器名称:

$ docker-compose -p MY_PROJECT_NAME

相当于(更易读):

$ docker-compose --project-name MY_PROJECT_NAME

关于docker-compose 名为 : "prefix_%s_1" instead of "%s" 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33045358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com