--- { title: "Docker内部网络连接错误的一种检查手段 nmap container", description: "文章讲述了排查容器内应用连接问题的方法。作者创建了一个nmap容器来检查`host.docker.internal`,发现该域名已不可用,实际应使用IP`172.17.0.1`。同时分享了在服务器无法拉取镜像时,通过`docker save`和`docker load`迁移本地镜像的解决方案。最后提到可直接在容器内启动Ubuntu并exec进入操作。", draft: false, type: "article", created_at: "2024-09-23T20:50:00+08:00", published_at: "2024-09-23T21:01:00+08:00", updated_at: [ "2024-09-23T21:01:00+08:00"], category: '个人', tags: [ "Docker" ], tech_stack: [ "Docker" ], tech_stack_percent: [ 1 ], tech_stack_icon_names: [ "mdi:docker" ], tech_stack_theme_colors: [ "#1c90ed" ], } --- !!!warning Legacy Article 过时的文章 此文章从旧博客迁移而来,编写时技术水平有限,仅供参考 !!! 最近被一个容器无法内应用无法连接的问题折磨住了,我想看看内部的host.docker.internal到底怎么回事,于是想到建立一个nmap container进去检查 Dockerfile: ``` # 使用官方的 Ubuntu 镜像作为基础镜像 FROM ubuntu:latest # 更新包列表并安装 nmap RUN apt-get update && apt-get install -y nmap # 创建一个目录来存储 nmap 结果 RUN mkdir /nmap_results # 运行 nmap 并将结果保存到文件中,同时打印到控制台 CMD ["sh", "-c", "nmap host.docker.internal > /nmap_results/nmap_results.log && cat /nmap_results/nmap_results.log"] ``` docker-compose.yml: ``` version: '3.4' services: nmap_service: image: nmap_image:latest build: context: . dockerfile: Dockerfile volumes: - ./nmap_results:/nmap_results ``` nmap结果发现不存在host.docker.internal,可能是docker更新的原因。之前是可用的,但现在变成了 `172.17.0.1` 另附服务器无法pull image时,使用其他机器本地image的方法 ``` # 机器一 docker save [imgID] > imagefile #机器二 docker load < imagefile docker tag [new_imgID] [随便什么名字]:[随便什么版本] ``` 最后改掉Dockerfile中的FROM就好了 写文章时我才想起来,可以直接docker内起ubuntu虚拟机,exec进去操作,忘了。