1. Host的IP地址获取
yinbodotcc@yay:~$ docker inspect --format '{{.NetworkSettings.IPAddress}}' jenkins_master
yinbodotcc@yay:~$ docker exec -it jenkins_master /bin/bash
jenkins@ca57ff3da874:/$ ip route
yinbodotcc@yay:~$ docker exec -it jenkins_master ip add | grep global
yinbodotcc@yay:~$ docker exec -it jenkins_master cat /etc/hosts
2. 暴露Host上的一个容器端口
2.1 待改进:在Host上访问容器里的这个应用(别的主机访问不了)
yinbodotcc@yay:~/dockerfiles$ docker build -f flaskDockerfile -t flask2 .
2.2 正常的做法
yinbodotcc@yay:~/dockerfiles$ docker kill foobar
foobar
yinbodotcc@yay:~/dockerfiles$ docker rm foobar
foobar
yinbodotcc@yay:~/dockerfiles$ docker run -d -p 5000 --name foobar flask2
yinbodotcc@yay:~/dockerfiles$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad80619f083e flask2 "python /tmp/hello.py" 10 minutes ago Up 7 minutes 0.0.0.0:32769->5000/tcp foobar
ca57ff3da874 jenkins "/bin/tini -- /usr/l…" 2 weeks ago Up 2 hours 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins_master
3. link 容器
yinbodotcc@yay:~$ docker run -d --name database -e MYSQL_ROOT_PASSWORD=root mysql:5.5
yinbodotcc@yay:~$ docker run -d --link database:db --name web runseb/hostname
yinbodotcc@yay:~$ docker run -d --link web:application --name lb nginx
|yinbodotcc@yay:~$ docker exec -it lb env | grep APPLICATION
APPLICATION_PORT=tcp://172.17.0.3:5000
APPLICATION_PORT_5000_TCP=tcp://172.17.0.3:5000
APPLICATION_PORT_5000_TCP_ADDR=172.17.0.3
APPLICATION_PORT_5000_TCP_PORT=5000
APPLICATION_PORT_5000_TCP_PROTO=tcp
APPLICATION_NAME=/lb/application
yinbodotcc@yay:~$ curl 172.17.0.3:5000
this is an example:132bb080d9e5yinbodotcc@yay:~$