为 docker run 配置选项 [英] Configuring options for docker run

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

问题描述

由于本地网络配置,我必须将 --dns 和 --dns-search 选项添加到我的 docker run 命令中,如下所示:

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

是否有环境变量或配置文件,我可以在其中添加 DNS 选项,这样我就不必在每次运行容器时都输入它们?

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?

我在 Ubuntu 16.04 上使用 docker,该 Ubuntu 16.04 在 Windows 机器上托管的 VMware VM 上运行.

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

谢谢.

推荐答案

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

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"]
}

然后使用 systemctl restart docker 重新启动 docker 守护进程以应用更改.

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

您可能会发现更新 VM 中的/etc/resolv.conf 以将此更改应用于不是 docker 容器而是 VM 本身会更好.那看起来像:

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

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

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.

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

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