One - One Code All

Blog Content

Docker容器端口映射

Linux-Mac 容器化 运维   2014-04-19 11:16:01

在Docker容器的日常使用中,有以下5种常见的端口映射方式

1.对容器暴露的所有端口,随机映射宿主机端口

-P , –publish-all=true | false,默认为false

# docker run -P -it ubuntu /bin/bash

2. 映射宿主机随机端口到容器指定端口

-p containerPort( -p表示 –publish=[ ] )

# docker run -p 80 -it ubuntu /bin/bash     

3. 映射宿主机指定端口到容器指定端口(一 一对应)

hostPort : containerPort

# docker run -p 8080:80 -it ubuntu /bin/bash

4. 指定容器IP和容器端口,宿主机端口随机映射

ip : : containerPort

# docker run -p 127.0.0.12::80 -it ubuntu /bin/bash

5. 指定容器IP、宿主机端口、容器端口

ip : hostPort : containerPort

# docker run -p 127.0.0.12:8080:80 -it ubuntu /bin/bash


上一篇:虚拟机与docker容器区别
下一篇:docker挂载本地目录

The minute you think of giving up, think of the reason why you held on so long.