带有新名称服务器的 Docker [英] Docker with a new nameserver

查看:20
本文介绍了带有新名称服务器的 Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 /etc/resolv.conf (dockerfile) 中添加新的名称服务器?

How I can add new nameserver in /etc/resolv.conf (dockerfile)?

在我使用的 dockerfile 上:

On my dockerfile I use:

FROM ubuntu:14.04

RUN echo "nameserver 10.111.122.1" >> /etc/resolv.conf

在我的测试中我使用:

docker run --rm 746cb98d6c9b echo cat /etc/resolv.conf

我没有得到我的更改(新的名称服务器)...所以我尝试使用

I didn't get my change (the new nameserver)... So I try adding mannualy with

docker run --rm 746cb98d6c9b echo "nameserver 10.111.122.1" >> /etc/resolv.conf 

我得到了

zsh: permission denied: /etc/resolv.conf

如何更改此文件的权限或使用 root 用户或在 docker 文件中使用 chmod?我真正的任务是为我构建这个 dockerfile 添加和 dns 服务器.

How I can change permission of this file OR use a root user OR use a chmod in docker files ? My real task is to add and dns server for my build of this dockerfile.

我正在使用 linux mint.

I'm using a linux mint.

我通过 docker run 命令(使用 --dns)进行 ping 测试得到了正确的结果

I'm get a correct result with a ping test on docker run command (with --dns)

推荐答案

因此,向容器的构建过程添加新 DNS 信息的方法之一是向 Docker 守护程序添加一些启动选项.该过程的文档显示您将选择的选项使用的是 --dns.配置文件的位置取决于您的特定发行版.在我的 Linux Mint 机器上,该文件位于 /etc/default/docker 中.在 Linux Mint 上,查找 DOCKER_OPTS= 行,并将适当的 --dns=x.x.x.x 条目添加到该行.

So, one of the ways you can add new DNS information to your container's build process is by adding some startup options to your Docker daemon. The documentation for that process reveals that the option you'll use is --dns. The location of your configuration file depends on your specific distro. On my Linux Mint machine, the file is in /etc/default/docker. On Linux Mint, look for the DOCKER_OPTS= line, and add the appropriate --dns=x.x.x.x entries to that line.

例如,如果您想使用 Google 的 DNS,您应该将该行更改为如下所示:

For example, if you want to use Google's DNS, you should change that line to look like this:

DOCKER_OPTS="--dns=8.8.4.4 --dns=8.8.8.8"

另外,在没有 --dns--dns-search 启动选项的情况下,Docker 将使用 /etc/resolv.conf.

Additionally, in the absense of --dns or --dns-search startup options, Docker will use the /etc/resolv.conf of the host it's running on instead.

这篇关于带有新名称服务器的 Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆