之前在ubuntu18.04上部署过docker,环境文件都在,但在ubuntu2204上部署时有异常。
docker安装参考:https://www.cnblogs.com/1million/p/15085034.html
#!/bin/sh
sudo service --status-all
sudo service docker start
sudo service docker restart
执行docker ps -a 时:提示Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
查看了docker的日志是报如下错误:
failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain: (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables): RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1
(exit status 4))
是iptables的问题,ubuntu22 默认情况下使用的是 iptables-nft ,通过以下命令修改:
update-alternatives --config iptables
选择 “iptables-legacy”
重启 docker 问题就解决了,不知道你和我是不是一样的问题,先看一下docker日志里的具体报错原因,日志在/var/log/docker.log 里。