參考教程:https://docs.docker.com/engine/reference/commandline/start/
環境
- virtual box 6.1
- centos 7.8
- docker 19.03
命令格式
docker start [OPTIONS] CONTAINER [CONTAINER...]
使用 start 命令可以啟動一個容器。
命令選項
由於命令選項有很多,下面選擇幾個常用的進行學習。
名稱 | 默認值 | 描述 |
---|---|---|
--attach , -a |
連接到標准輸出流 | |
--detach-keys |
定義后台運行容器的按鍵 | |
--interactive , -i |
連接到標准輸出流 |
示例
啟動后台容器
# 拉取鏡像
[root@master docker]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
# 創建容器
[root@master docker]# docker create nginx
bf0e4bfd796c43f53b052611bac5c260d457606dd9150c512ef48137962c2d04
# 啟動容器
[root@master docker]# docker start bf
bf
# 查看容器 IP
[root@master docker]# docker inspect bf -f '{{json .NetworkSettings.Networks.bridge.IPAddress}}'
"172.17.0.3"
# 訪問 nginx
[root@master docker]# curl 172.17.0.3:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
啟動交互式容器
[root@master docker]# docker create -it busybox /bin/sh
69575a4213c1ace85b198f3a94b50acc21a3e96ee3429b48ef9d72a39f0f250a
[root@master docker]# docker start -i 69
/ # ls
bin dev etc home proc root sys tmp usr var
/ #
總結
介紹了 start 命令的使用,可以運行一個創建好的容器,同時也可以運行已經停止的容器。