【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
docker ps
- Lists containers.docker logs
- Shows us the standard output of a container.docker stop
- Stops running containers.
Running a Web Application in Docker
// -P告诉Docker映射所需要的端口到本地主机
$ docker run -d -P training/webapp python app.py
Viewing our Web Application Container
// -l显示详细信息
$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse
//Docker将容器的5000端口映射到主机的49155端口,此时可以通过localhost:49155访问网站了
//上面的-P标签相当于-p 5000,以下是自定义端口映射关系,将容器的5000端口映射到主机的5000端口
$ docker run -d -p 5000:5000 training/webapp python app.py
//查看容器ubuntu:14.04的5000端口映射主机的端口
$ docker port CONTAINERID[3~4] 5000
0.0.0.0:49155
//查看容器ubuntu:14.04的输出,-f 的效果类似tail -f
$ docker logs -f CONTAINERID[3~4]
* Running on http://0.0.0.0:5000/
10.0.2.2 - - [23/May/2014 20:16:31] "GET / HTTP/1.1" 200 -
10.0.2.2 - - [23/May/2014 20:16:31] "GET /favicon.ico HTTP/1.1" 404 -
//查看容器的
$ docker top CONTAINERID[3~4]
PID USER COMMAND
854 root python app.py
//查看容器对应的IP
luoo@PS:~$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' 3589
172.17.0.8
//停止容器
$ docker stop CONTAINERID[3~4]
//删除容器
$ docker rm CONTAINERID[3~4]
来源:oschina
链接:https://my.oschina.net/u/270815/blog/619607