DockerCompose常见问题整理

Docker Compose 常见问题整理

容器内部无法通信

将容器处于同一个自定义网络即可

1
2
3
4
5
6
7
8
9
10
11
services:
mysql:
networks:
- test-network
nacos:
networks:
- test-network

networks:
test-network:
external: true

MySQL 无法执行初始化 sql

需要保证 mysql/data 目录为空

1
2
volumes:
- ./mysql/initdb:/docker-entrypoint-initdb.d

WARNING,需要设置 ‘vm.overcommit_memory = 1’

提示: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.
解决:

1
2
3
wsl --list --verbose
wsl -d docker-deskstop
sysctl vm.overcommit_memory=1

Redis 指定配置文件启动失败

原因:配置文件设置了 daemonize yes,与 compose up -d 冲突
解决:设置 daemonize no

端口不可用

netstat -ano | findstr 8080,查看端口是否真的没有占用

提示:Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:8080 -> 0.0.0.0:0: listen tcp 0.0.0.0:8080: bind: An attempt was made to access a socket in a way forbidden by its access p ermissions.

解决:

1
2
3
4
5
https://medium.com/@sevenall/completely-solve-the-problem-of-docker-containers-not-starting-or-running-on-windows-10-due-to-port-57f16ed6143

netsh int ipv4 set dynamic tcp start=49152 num=16384
netsh int ipv6 set dynamic tcp start=49152 num=16384
重启电脑