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

查看:73
本文介绍了带有新名称服务器的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天全站免登陆