配置码头运行的选项 [英] Configuring options for docker run

查看:252
本文介绍了配置码头运行的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于本地网络配置,我必须向docker运行命令添加--dns和--dns-search选项,如下所示:

  docker运行--dns XX.XX.1.1 --dns-search companydomain -t mycontainer 

有没有一个环境变量或配置文件,我可以在其中添加DNS选项,以便每次我想要运行一个容器时都不必输入它们。



我在Ubuntu 16.04上使用Docker,在Windows机器上托管的VMware VM上运行。



谢谢。

解决方案

您可以将这些选项作为运行的所有容器的默认值添加到docker守护程序中。在 dockerd 命令行中,选项相同, - dns XX.XX.1.1 --dns-search companydomain 。为了避免更改启动脚本来添加该选项,可以使用以下内容来设置/etc/docker/daemon.json文件:

  {
dns:[XX.XX.1.1],
dns-search:[companydomain]
}

然后使用 systemctl restart docker 重新启动docker守护程序以应用更改。 / p>

您可能会更好地更新VM中的/etc/resolv.conf,以将此更改应用于Docker容器,而不是VM本身。这将是:

  nameserver XX.XX.1.1 
搜索companydomain

如果更新resolv.conf,请确保它不受其他工具管理,例如如果您正在获取虚拟机的dhcp地址,这将被dhcp客户端守护程序覆盖。


Due to local network configuration I have to add --dns and --dns-search options to my docker run commands like so:

docker run --dns XX.XX.1.1 --dns-search companydomain -t mycontainer

Is there an environment variable or config file where I can add the DNS options so that I don't have to type them each time I want to run a container?

I'm using docker on Ubuntu 16.04 running on VMware VM hosted on a Windows machine.

Thank you.

解决方案

You can add these options to the docker daemon as the default for all the containers it runs. On the dockerd command line, the options are the same, --dns XX.XX.1.1 --dns-search companydomain. To avoid changing the startup scripts to add that option, it's easier to setup an /etc/docker/daemon.json file with the following contents:

{
  "dns": ["XX.XX.1.1"],
  "dns-search": ["companydomain"]
}

Then restart the docker daemon with systemctl restart docker to apply the change.

You may find it better to update the /etc/resolv.conf in your VM to apply this change to not on the docker containers, but the VM itself. That would look like:

nameserver XX.XX.1.1
search companydomain

If updating the resolv.conf, be sure that it's not managed by another tool, e.g. if you are getting dhcp addresses for your VM this would be overwritten by the dhcp client daemon.

这篇关于配置码头运行的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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