Docker平臺的基本使用方法

1.運行一個 container並加載鏡像centos,運行起來這個實例後,在實例中執行 /bin/bash命令docker

docker經常使用參數:centos

run  運行bash

  • -i  以交互模式運行容器,一般與 -t 同時使用;
  • -t  爲容器從新分配一個,僞輸入終端,一般與 -i 同時使用;

 

$ docker run -it centos:latest /bin/bash
$ exit

 

2.在 container 中啓動一個長久運行的進程,不斷向stdin輸出 hello world 。模擬一個後臺運行的服務spa

 

 

docker經常使用參數:3d

 

  • -d  後臺運行容器,並返回容器ID;
  • -c  後面跟待完成的命令

 

$ docker run  -d docker.io/centos:latest /bin/sh -c "while true;do echo hello world; sleep 1; done" 1b3493487c4fde6eb233d59fa9ab9a204ad993cd3debbd5a9a28be6816694605#容器的id

 

從一個容器中取日誌,查看輸出的內容 日誌

語法: docker  logs   容器實例的Name/ID code

$ docker logs 1b3493487c4 #容器的ID能夠寫全,也能夠不寫全,只要惟一就能夠了
hello world
hello world
hello world
hello world

3.建立並運行一個容器blog

$ docker run 

4.開啓一個已存在的容器進程

$ docker start id

5.查看正在運行的容器it

$ docker ps #(-a 列出全部容器,包含沉睡/退出狀態的容器)

6.關閉一個容器

$ docker stop id

7.強制關閉一個容器

$ docker kill id

8.刪除一個容器

$ docker rm id #(-f 強制刪除)
相關文章
相關標籤/搜索