Docker容器(三)——容器端口映射
2024-08-26 11:49:25
(1).容器端口映射
容器的端口映射用到了-p选项,-p [物理机端口]:[容器实例端口]
让centos:httpd运行在后台
[root@youxi1 ~]# docker run -d -p 80:80 centos:httpd
92c1d60be419a06d24f6a8eb4c60e89a5d5e6652087ffa73bd86be320fa589e0
[root@youxi1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp jovial_chebyshev
接着使用浏览器访问
查看物理机上开启的80代理端口
[root@youxi1 ~]# yum -y install net-tools
[root@youxi1 ~]# netstat -antup | grep 80
tcp 0 0 192.168.5.101:46116 114.80.24.198:80 TIME_WAIT -
tcp 0 0 192.168.5.101:36968 114.80.24.199:80 TIME_WAIT -
tcp 0 0 192.168.5.101:58516 114.80.24.201:80 TIME_WAIT -
tcp 0 0 192.168.5.101:46120 114.80.24.198:80 TIME_WAIT -
tcp 0 0 192.168.5.101:60010 114.80.24.203:443 TIME_WAIT -
tcp6 0 0 :::80 :::* LISTEN 5040/docker-proxy //这一条
udp 0 0 127.0.0.1:323 0.0.0.0:* 801/chronyd
udp6 0 0 ::1:323 :::* 801/chronyd
(2).访问后台运行的容器实例
语法:docker exec -it [容器ID|镜像名称] /bin/bash
进入后台运行的容器实例,查看容器的IP地址
[root@youxi1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 13 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp jovial_chebyshev
[root@youxi1 ~]# docker exec -it 92c1d60be419 /bin/bash
[root@92c1d60be419 /]# yum -y install net-tools
[root@92c1d60be419 /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255 //容器实例的IP地址
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 83 bytes 319729 (312.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 68 bytes 4649 (4.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在看一下物理机的IP地址
[root@youxi1 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 //这个IP与容器实例处于同网段
inet6 fe80::42:24ff:fe5d:36c1 prefixlen 64 scopeid 0x20<link>
ether 02:42:24:5d:36:c1 txqueuelen 0 (Ethernet)
RX packets 8209 bytes 333975 (326.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12228 bytes 40934054 (39.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.5.101 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::201:7257:85b:7dc8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e6:d6:27 txqueuelen 1000 (Ethernet)
RX packets 177898 bytes 60097281 (57.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 112125 bytes 155022609 (147.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 32 bytes 2592 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 2592 (2.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethf3eac0e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::8098:68ff:fed3:5ad7 prefixlen 64 scopeid 0x20<link>
ether 82:98:68:d3:5a:d7 txqueuelen 0 (Ethernet)
RX packets 81 bytes 5530 (5.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 98 bytes 321124 (313.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
最新文章
- Django基础,Day3 - 编写 django admin
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- ab压力测试和CC预防
- 深入.NET框架
- MySQL 中NULL和空值的区别 (转载 http://blog.sina.com.cn/s/blog_3f2a82610102v4dn.html)
- 夺命雷公狗ThinkPHP项目之----企业网站3之后台栏目页的搭建(百度编辑器的引入)
- 以Server模式启动Derby服务竟然抛套接字权限异常
- Qt使用MinGW编译,如何忽略警告
- vb6.0 倒计时
- easyUI带复选框的组合树
- 基于C#的数据库文件管理助手
- Luogu P3165 [CQOI2014]排序机械臂
- 查看CPU 内存 硬盘 网络 查看进程使用的文件 uptime top ps -aux vmstat iostat iotop nload iptraf nethogs
- SQL语句汇总(三)——聚合函数、分组、子查询及组合查询
- cf1061c 普通dp题
- BAT 大规模Hadoop集群实践
- hdu 5073 有坑+方差贪心
- html-文件上传设置accept类型延时问题
- 前端学PHP之会话Session
- Entity Framework 同一个上下文中,如何进行对同一个实体进行指定字段更新
热门文章
- 4.3 axios
- C++类中构造函数调用构造函数问题
- PAT乙级1040 有几个PAT
- Kubernetes 学习23 kubernetes资源指标API及自定义指标API
- (尚002)Vue的基本使用
- my.conf
- mysqli类的对象和其属性方法;mysqli类面向过程的属性和方法
- matlab 万能实用的非线性曲线拟合方法
- ORA-01578: ORACLE 数据块损坏 (文件号 13, 块号 2415081) ORA-01110: 数据文件XXXXXX
- 读取中文文件到CString