docker官方文档中的dns,link,expose,publish

简介: link是过时的了,尽量不要用。 dns内部集成,也可以用外部。 expose只是用于记录,并不真的。 publish是否起作用,也要看情况,是否被占用端口。 --------------------------------------   Embedded DNS server Do...

link是过时的了,尽量不要用。

dns内部集成,也可以用外部。

expose只是用于记录,并不真的。

publish是否起作用,也要看情况,是否被占用端口。

--------------------------------------

 

Embedded DNS server

Docker daemon runs an embedded DNS server which provides DNS resolution among containers connected to the same user-defined network, so that these containers can resolve container names to IP addresses. If the embedded DNS server is unable to resolve the request, it will be forwarded to any external DNS servers configured for the container. To facilitate this when the container is created, only the embedded DNS server reachable at 127.0.0.11 will be listed in the container’s resolv.conf file. For more information on embedded DNS server on user-defined networks, see embedded DNS server in user-defined networks

Exposing and publishing ports

In Docker networking, there are two different mechanisms that directly involve network ports: exposing and publishing ports. This applies to the default bridge network and user-defined bridge networks.

  • You expose ports using the EXPOSE keyword in the Dockerfile or the --expose flag to docker run. Exposing ports is a way of documenting which ports are used, but does not actually map or open any ports. Exposing ports is optional.
  • You publish ports using the PUBLISH keyword in the Dockerfile or the --publish flag to docker run. This tells Docker which ports to open on the container’s network interface. When a port is published, it is mapped to an available high-order port (higher than 30000) on the host machine, unless you specify the port to map to on the host machine at runtime. You cannot specify the port to map to on the host machine in the Dockerfile, because there is no way to guarantee that the port will be available on the host machine where you run the image.

    This example publishes port 80 in the container to a random high port (in this case, 32768) on the host machine.

    $ docker run -it -p 80 nginx
    
    $ docker ps
    
    64879472feea        nginx               "nginx -g 'daemon ..."   43 hours ago        Up About a minute   443/tcp, 0.0.0.0:32768->80/tcp   blissful_mclean
    
    

    The next example specifies that port 80 should be mapped to port 8080 on the host machine. It will fail if port 8080 is not available.

    $ docker run -it -p 80:8080 nginx
    
    $ docker ps
    
    b9788c7adca3        nginx               "nginx -g 'daemon ..."   43 hours ago        Up 3 seconds        80/tcp, 443/tcp, 0.0.0.0:80->8080/tcp   goofy_brahmagupta
    

Links

Before Docker included user-defined networks, you could use the Docker --link feature to allow a container to resolve another container’s name to an IP address, and also give it access to the linked container’s environment variables. Where possible, you should avoid using the legacy --link flag.

When you create links, they behave differently when you use the default bridge network or when you use user-defined bridge networks. For more information, see Legacy Links for link feature in default bridge network and the linking containers in user-defined networks for links functionality in user-defined networks.

目录
相关文章
|
数据库 Docker 容器
Docker之容器互联--link
Docker之容器互联--link
412 0
|
存储 Unix 数据安全/隐私保护
Docker官方文档学习笔记(三):总结与补充
Docker官方文档学习笔记(三):总结与补充
584 0
Docker官方文档学习笔记(三):总结与补充
|
存储 资源调度 关系型数据库
Docker官方文档学习笔记(二):Docker Desktop入门
Docker官方文档学习笔记(二):Docker Desktop入门
4580 0
Docker官方文档学习笔记(二):Docker Desktop入门
|
Kubernetes Ubuntu 网络协议
Docker官方文档学习笔记(一):安装、升级、卸载Docker Desktop for Linux(和安装Docker Engine二选一,推荐Docker Engine)
Docker官方文档学习笔记(一):安装、升级、卸载Docker Desktop for Linux(和安装Docker Engine二选一,推荐Docker Engine)
1681 1
Docker官方文档学习笔记(一):安装、升级、卸载Docker Desktop for Linux(和安装Docker Engine二选一,推荐Docker Engine)
|
存储 Ubuntu 网络协议
Docker官方文档学习笔记(一):安装Docker Engine(和安装Docker Desktop for Linux二选一)
Docker官方文档学习笔记(一):安装Docker Engine(和安装Docker Desktop for Linux二选一)
1592 0
|
应用服务中间件 nginx Docker
docker笔记:docker容器通信参数 --link参数介绍
同一个宿主主机上的多个docker容器之间如果需要进行通信,第一种最容易想到的方式就是使用容器自身的ip地址、宿主主机的ip+容器暴露出的端口号来通信,我们知道默认情况下docker重新run后,对应的IP地址就会改变,这样如果两个容器之间通信就会变得非常麻烦,每次都要修改通信的IP地址。这个时候 --link参数就派上大用场了,它会给要链接的容器设定一个通信的别名,即使重启后IP地址发生了改变,依然可以正常通信。
docker笔记:docker容器通信参数 --link参数介绍
|
安全 应用服务中间件 Docker
Docker 容器互联 --link 和 自定义网络
本文是博主学习docker 容器互联的记录,希望对大家有所帮助
696 0
Docker 容器互联 --link 和 自定义网络
|
Docker 容器
Docker - 网络 Link
Docker - 网络 Link
216 0
|
Docker 容器
Docker----容器名互联link技术及其本质
Docker----容器名互联link技术及其本质
319 0
|
域名解析 网络协议 应用服务中间件
Docker——--link实现容器互联
Docker——--link实现容器互联
1165 0

相关产品

  • 云解析DNS