最近被一个容器无法内应用无法连接的问题折磨住了,我想看看内部的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进去操作,忘了。