服务不会在 docker-compose ps 中列出。另外docker将其创建为容器,执行 docker ps 时可以看到它。
我重新启动了docker桌面,也重新启动了计算机,没有任何改变。
redisabc:
container_name: redis
image: redis
command: [ "redis-server", "--protected-mode", "no" ]
hostname: redis
restart: always
ports:
- 6379:6379
networks:
- backend
如您所见,键入docker-compose ps时没有名为redisabc的服务
如果我将服务名称redisabc重新改回redis,一切将按预期工作
重要编辑::我用另一台计算机测试了所有内容,但未显示任何问题。我想知道是否可以在docker上刷新所有服务的缓存机制?我真的对发生的事情感到困惑。
答案 0 :(得分:0)
我将重写答案,因为我认为我没有太大帮助。
通过以下方法查看我在家里复制的所有信息:
docker-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
已使用的服务名称。
答案 1 :(得分:0)
尝试了几乎所有内容(从docker system prune --volumes到卸载docker machine等很多东西)后,我已经找到了确切的事件
我有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 。