docker run: 启动一个docker容器
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
- -d: 后台运行容器,并返回容器ID;(detached)
- -i: 以交互模式运行容器,通常与 -t 同时使用;(interactive)
- -t: 启动一个bash终端(terminal)
说明:-t 让Docker分配一个伪终端(pseudo-tty)并绑定到容器的标准输入上, -i 则让容器的标准输入保持打开 - -p: 将容器端口映射到本地端口
-p localport:dockerport
docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
宿主的80将映射到容器的8080 - -v 将宿主机目录挂载到容器
-v localfile:dockerfile
- -e 设置容器的环境变量 eg.
-e "addr=http://example.com"
docker ps
查看正在运行的容器:
runoob@runoob:~# docker ps
CONTAINER ID IMAGE COMMAND ... PORTS
d3d5e39ed9d3 training/webapp "python app.py" ... 0.0.0.0:32769->5000/tcp
这里多了端口信息。
PORTS
0.0.0.0:32769->5000/tcp
表示宿主机端口 32769 映射到Docker 5000 端口(默认 Python Flask 端口),或者说Docker 5000 端口绑定了宿主机32769端口
docker stop / docker kill
亲测stop会比kill耗时,kill会直接杀死运行中的container
So ideally we always stop a container with the docker stop command in order to get the running process inside of it a little bit of time to shut itself down, otherwise if it feels like the container has locked up and it's not responding to the docker stop command then we could issue docker kill instead.
网友评论