首页 > 解决方案 > 在 CentOS 中部署 docker 容器时 DNS 无法解析

问题描述

尝试在 Cent-OS 中部署 docker 容器时出现以下错误( DNS 未在容器内解析)

error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads https://github.com/Asymmetrik/node-fhir-server-core.git
Directory: /srv/cpr-fhir
Output:
fatal: unable to access 'https://github.com/Asymmetrik/node-fhir-server-core.git/': Could not resolve host: github.com

**Operating System: CentOS Linux 8 (Core)
Docker version: Version:           19.03.7**

标签: dockercentoscentos7centos8

解决方案


实际上这是因为 docker 容器没有使用本机 DNS。

使固定

进入docker配置文件 /lib/systemd/system/docker.service

在 ExecStart 命令中附加 dns 变量,如下所示

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --dns 8.8.8.8


推荐阅读