Docker部署服务报错及解决方案

本文解决Docker部署中因使用host网络模式并同时进行端口映射导致的错误,以及IDEA环境下找不到docker-compose命令的问题。通过调整docker-compose配置文件及正确引用docker-compose命令,确保服务成功部署。

报错1

报错信息如下图所示:docker-compose idea CreateProcess error=2, 系统找不到指定的文件
在这里插入图片描述
解决方案:IDEA执行docker-compose命令需要对应的可执行文件,而Windows上面没有这个命令。所以需要下载Docker,引用Docker安装目录下docker-compose命令。
如图,将红框的内容替换为C:\Program Files\Docker\Docker\resources\bin\docker-compose.exe
在这里插入图片描述

报错2

Docker部署xxx-xxxxx-xxx服务,报错信息如下:

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating xxx-xxxxx-xxx ... 

ERROR: for xxx-xxxxx-xxx  "host" network_mode is incompatible with port_bindings

ERROR: for xxx-xxxxx-xxx  "host" network_mode is incompatible with port_bindings
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose\cli\main.py", line 81, in main
  File "compose\cli\main.py", line 203, in perform_command
  File "compose\metrics\decorator.py", line 18, in wrapper
  File "compose\cli\main.py", line 1186, in up
  File "compose\cli\main.py", line 1166, in up
  File "compose\project.py", line 697, in up
  File "compose\parallel.py", line 108, in parallel_execute
  File "compose\parallel.py", line 206, in producer
  File "compose\project.py", line 679, in do
  File "compose\service.py", line 559, in execute_convergence_plan
  File "compose\service.py", line 473, in _execute_convergence_create
  File "compose\parallel.py", line 108, in parallel_execute
  File "compose\parallel.py", line 206, in producer
  File "compose\service.py", line 478, in <lambda>
  File "compose\service.py", line 457, in create_and_start
  File "compose\service.py", line 330, in create_container
  File "compose\service.py", line 939, in _get_container_create_options
  File "compose\service.py", line 1014, in _get_container_host_config
  File "docker\api\container.py", line 598, in create_host_config
  File "docker\types\containers.py", line 338, in __init__
docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings
[24496] Failed to execute script docker-compose
Failed to deploy 'Compose: xxx-app': `docker-compose` process finished with exit code -1

报错原因: "host" network_mode is incompatible with port_bindings(host网络模式与端口映射不兼容)
错误定位:Docker compose file(docker-compose-dev.yml),内容如下所示

version: "2"
services:
  xxx-xxxxx-xxx:
    build: .
    	...
    network_mode: host
    image: xxx-xxxxx-xxx
    ports:
      - 9010:9010
    ...

network_mode: host网络模式设置为host,即host模式下容器不会获得一个独立的network namespace,而是与宿主机共用一个。这就意味着容器不会有自己的网卡信息,而是使用宿主机的。在这种情况下,所有端口是与宿主机同步,我们访问宿主机端口就能访问我们的容器,再作端口映射是本机映射到本机,多此一举。
解决方案:修改docker-compose-dev.yml文件,删除ports配置

version: "2"
services:
  xxx-xxxxx-xxx:
    build: .
    	...
    network_mode: host
    image: xxx-xxxxx-xxx
    ...

相关链接:https://blog.csdn.net/mahui_1980/article/details/114972555

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值