问题描述
在打开防火墙的情况下,通过http启动docker容器报500错误
解决过程
1.查看2375端口是否开放
firewall-cmd --query-port=2375/tcp
2.检查外部网络是否可以访问服务器
直接在浏览器输入http://192.xxx.xxx.xxx:2375/containers/json?all=true
看是否有返回
结果是有返回,代表外部网络连接服务器没问题
3.查看ip转发
sysctl net.ipv4.ip_forward
坑
看起来ip转发是正常的,但问题也就出现在这里,查看/etc/sysctl.conf文件,发现里面并没有ip转发相关配置
cat /etc/sysctl.conf
4.成功解决
在 /etc/sysctl.conf里,将net.ipv4.ip_forward=1
添加进去就好文章来源:https://www.toymoban.com/news/detail-536341.html
[root@xxx ~]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward=1
之后再重新加载配置文件和重启docker文章来源地址https://www.toymoban.com/news/detail-536341.html
systemctl daemon-reload
systemctl restart docker
5.测试
@Test
public void startDocker(){
String url="http://192.xxx.xxx.xxx:2375";
String envId="n8fd1c2e61cf7963e5b1c9c1af00b8134e5c71915059c4a465fb3bad827abb19f";
restTemplate.postForObject(url + "/containers/" + envId + "/start", null, Object.class);
}
到了这里,关于记一次问题解决:通过http启动docker容器报500错误的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!