一直听说docker-compose是好东西,一直没用上。今天有时间学习下:https://www.runoob.com/docker/docker-compose.html。
问题现象
执行docker-compose up的时候报错
(base) [root@VM-100-213-centos ~/composetest]# docker-compose up
Creating network "composetest_default" with the default driver
ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
尝试方法
先查看networks,执行prune,问题依旧
(base) [root@VM-100-213-centos ~/composetest]# docker network ls
NETWORK ID NAME DRIVER SCOPE
f5789b1eaa7b bridge bridge local
a09d489d2abd host host local
ef2dbca65b2a none null local
(base) [root@VM-100-213-centos ~/composetest]# docker network prune
WARNING! This will remove all networks not used by at least one container.
Are you sure you want to continue? [y/N] y
(base) [root@VM-100-213-centos ~/composetest]# docker-compose up
Creating network "composetest_default" with the default driver
ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
(base) [root@VM-100-213-centos ~/composetest]#
执行docker network rm试试
(base) [root@VM-100-213-centos ~/composetest]# docker network rm $(docker network ls -q)
Error response from daemon: bridge is a pre-defined network and cannot be removed
Error response from daemon: host is a pre-defined network and cannot be removed
Error response from daemon: none is a pre-defined network and cannot be removed
原来docker默认有3种网络:bridge、host、none,这三个网络是不能被删除的。所以,网上常见的解决方法不适用。
解决方法
方法一
在docker-compose.yml中指定网络配置
networks:
default:
driver: bridge
ipam:
config:
- subnet: 172.31.1.0/24
方法二
首先手动创建网络
docker network create my-network --subnet 172.31.1.0/24
然后在docker-compose.yml指定上面创建的网络。将下面一段配置,添加到docker-compose.yml文件底部
networks:
default:
external:
name: my-network