原文:http://www.javashuo.com/article/p-qwewtcoj-mz.htmlhtml
$docker run -i -t <image_name/continar_id> /bin/bash
$docker run -d -it image_name
ps:這裏的 image_name 包含了tag:hello.demo.kdemo:v1.0docker
docker attach <id、container_name>
docker exec -t -i <id/container_name> /bin/bash
ps:docker exec是如此的有用,以致於咱們一般是將其封裝爲一個腳本,放到全局可調用的地方,好比,能夠寫成一個indocker.sh:bash
$cat indocker.sh docker exec -t -i $1 /bin/bash # 查看須要附着的容器id $docker ps | less -S CONTAINER ID IMAGE 9cf7b563f689 hello.demo.kdemo:v160525.202747 $./indocker.sh 9cf7b563f689
docker logs <id/container_name>
docker logs -f <id/container_name> (相似 tail -f) (帶上時間戳-t)
$docker ps
$docker ps | less -S
$docker ps -a
$docker ps -l
$docker top Name/ID
$docker inspect <id/container_name>
$docker run image_name apt-get install -y app_name
Note: 在執行apt-get 命令的時候,要帶上-y參數。若是不指定-y參數的話,apt-get命令會進入交互模式,須要用戶輸入命令來進行確認,但在docker環境中是沒法響應這種交互的。apt-get 命令執行完畢以後,容器就會中止,但對容器的改動不會丟失。網絡
$docker cp Name:/container_path to_path $docker cp ID:/container_path to_path
$docker commit ID new_image_name
Note: image至關於類,container至關於實例,不過能夠動態給實例安裝新軟件,而後把這個container用commit命令固化成一個image。app
$docker rm Name/ID
-f, –force=false; -l, –link=false Remove the specified link and not the underlying container; -v, –volumes=false Remove the volumes associated to the containerless
$docker rm `docker ps -a -q`
$docker stop Name/ID $docker start Name/ID $docker kill Name/ID $docker restart name/ID
$sudo docker images
-a, –all=false Show all images; –no-trunc=false Don’t truncate output; -q, –quiet=false Only show numeric IDsdom
$docker search image_name
$docker pull image_name
$docker rmi image_name
-f, –force=false Force; –no-prune=false Do not delete untagged parentsui
$docker history image_name
$docker push new_image_name
ps:要發佈到私有Registry中的鏡像,在鏡像命名中須要帶上Registry的域名(若是非80端口,同時須要帶上端口號)好比:spa
$docker push dockerhub.yourdomain.com:443/hello.demo.kdemo:v1.0
$docker pull image_name
$ip a show docker0
$docker inspect -f '{{ .NetworkSettings.IPAddress }}' <id、container_name>
附着到容器內部查看其內部ip:rest
$ip a show eth0
$docker version
$docker info
Ctrl+P+Q
docker cp foo.txt mycontainer:/foo.txt