为什么服务没有列在docker-compose ps中,当它的名字改变了?

问题描述 投票:0回答:2

当docker-compose文件中的服务名称更改时,服务将不会在docker-compose ps中列出,例如从redis到redisabc,如下所示。另外,docker将其创建为容器,可以在docker ps执行时看到它。

我重新启动了docker desktop并且还重启了机器没有任何改变。

我的docker-compose文件版本是3.6 enter image description here

  redisabc:
   container_name: redis
   image: redis
   command: [ "redis-server", "--protected-mode", "no" ]
   hostname: redis
   restart: always
   ports:
    - 6379:6379
   networks:
    - backend

如你所见,当键入docker-compose ps enter image description here时,没有名为redisabc的服务

但它仍然作为容器(docker ps result)enter image description here

这就是我创建docker-compose文件enter image description here的方式

如果我再次将服务名称redisabc更改为redis,那么一切都按预期工作enter image description here

重要编辑:我用另一台计算机测试了一切,没有显示任何问题。我想知道Docker上的服务是否有任何缓存机制可以刷新所有?我对发生的事情感到很困惑。

docker docker-compose
2个回答
0
投票

我会改写我的答案,因为我觉得我没多大帮助。

查看我在家中复制您的设置的所有信息,包括以下内容:

码头工人,compose.yml:

version: '3'
services:
  redisabc:
    image: "redis"
    command: [ "redis-server", "--protected-mode", "no" ]
    hostname: redis
    restart: always
    ports:
      - 6379:6379

然后我开始了:

# docker-compose up
Creating docker_redisabc_1 ... done
Attaching to docker_redisabc_1
redisabc_1  | 1:C 28 Mar 2019 21:23:43.775 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redisabc_1  | 1:C 28 Mar 2019 21:23:43.775 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
redisabc_1  | 1:C 28 Mar 2019 21:23:43.775 # Configuration loaded
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 * Running mode=standalone, port=6379.
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 # Server initialized
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redisabc_1  | 1:M 28 Mar 2019 21:23:43.776 * Ready to accept connections

ps的输出:

# docker-compose ps
      Name                     Command               State           Ports         
-----------------------------------------------------------------------------------
docker_redisabc_1   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp

它已被使用的服务名称。


0
投票

在尝试了几乎所有的东西之后我发现了确切的事件(很多东西从docker系统修剪 - 体积到卸载docker机器等)

我有2个不同的docker文件名为base-docker-compose.yml和docker-compose.yml。在服务创建期间,我通过base-docker-compose.yml文件调用docker-compose。创建服务之后我在没有base-docker-compose.yml文件的情况下使用docker-compose ps,尽管在执行时使用了base-docker-compose.yml。然后我做了docker-compose ps来列出整个服务。这是我犯的错误,我不得不使用docker-compose -f base-docker-compose.yml ps。

© www.soinside.com 2019 - 2024. All rights reserved.