Windows安装Linux子系统
Windows中Linux子系统(Ubuntu)使用问题
问题记录
安装Ubuntu后启动docker服务报错
报错:
Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?
启动docker,如启动失败查看失败原因
# 启动docker
service docker start
# 查看失败原因
systemctl status docker.service
# docker客户端连接HOST取消设置
unset DOCKER_HOST
常见失败原因:
docker启动配置文件路径:/lib/systemd/system/docker.service
docker启动配置daemon.json路径:/etc/docker/daemon.json(可能不存在,可直接创建,与docker.service配置搭配使用)
- Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.
- 查看上面具体问题说明,这个只是通用语
- is running问题
- 设置了客户端连接daemon的地址,导致docker服务地址与连接地址不一致
- 取消HOST设置:unset DOCKER_HOST
- 或者修改daemon服务地址比如tcp协议地址(可以远程访问),注意需要确认端口号开放
- 下图为一些不当的瞎几把操作(unset,export DOCKER_HOST......)
systemctl start docker服务报错
报错:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
问题原因:未安装systemctl导致
解决方案:安装systemctl,以下安装方式在Ubuntu子系统使用成功
执行以下2条命令:
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
安装ssh服务无法使用外部客户端连接
解决方案:
使用127.0.0.1:22登录
修改ssh配置/etc/ssh/sshd_config
# 修改允许root连接
PermitRootLogin yes
# 修改允许通过密码连接
PasswordAuthentication yes
然后重启服务即可:service ssh --full-restart
安装docker启动MySQL等服务局域网无法访问
原因及解决方案:
- docker使用的网络默认为桥接模式:bridge,简单起见可使用host模式(使用宿主机的网络)
- Windows访问子系统的服务需进行端口转发,将子系统的ip及端口在Windows系统上做一次转发
# 将本地6379端口转发到子系统的对应端口(示例172.17.192.103为子系统IP地址)
netsh interface portproxy add v4tov4 listenport=6379 listenaddress=* connectport=6379 connectaddress=172.17.192.103 protocol=tcp
# 查询端口转发配置
netsh interface portproxy show all