Docker 端口映射

Port Mapping

$ sudo docker run -d -p 5000:5000 training/webapp python app.py
5a690617994cd1a3a751acb6f14e8a35b5f1bbfd44ed9ddf8243ef625ca8feba
$ sudo docker logs 5a
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
192.168.33.1 - - [15/Oct/2017 04:32:22] "GET / HTTP/1.1" 200 -
192.168.33.1 - - [15/Oct/2017 04:32:22] "GET /favicon.ico HTTP/1.1" 404 -
$ sudo docker run -d -P training/webapp python app.py
d8f296292ad0f7b55036e79c7295cc71d3a6c183ce05278a8175b4345b1f4099
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
d8f296292ad0        training/webapp     "python app.py"     8 seconds ago       Up 7 seconds        0.0.0.0:32771->5000/tcp   wonderful_galileo

> # visit: localhost:32771
> # -P: random port

$ sudo docker stop d8
$ sudo rm d8
-p
HostPort:ContainerPort
HostIP:HostPort:ContainerPort
HostIP::ContainerPort # random port
[/udp]

Lookup

$ sudo docker port wonderful_galileo
5000/tcp -> 0.0.0.0:32771
$ sudo docker port wonderful_galileo 5000
0.0.0.0:32771

Linking

--name 
--link name:alias # link two containers
sudo docker ps -a
sudo docker inspect -f "{{ .Name }}" 
sudo docker run --rm ... # remove container automaticly when container stop

你可能感兴趣的:(Docker 端口映射)