docker之基礎實例
1.安裝docker:
#yum install docker
或
$sudo apt-get install docker.io
#systemctl enable docker
2.從官方registry搜索p_w_picpath
#docker search centos
3.從官方registry下載p_w_picpath
#docker pull centos
4.使用下載好的鏡像在前臺創建一個container的實例。指定容器名稱爲test,併爲其安裝vim。
#docker run -i -t centos --name test /bin/bash
root@xxxxxxxx:/# yum -y install vim
root@xxxxxxxx:/# exit
#
5.使用修改過的container創建一個新的p_w_picpath副本。
#docker commit -a “ggvylf” -m “install vim” test centos:test
6.查看本地的p_w_picpath:
#docker p_w_picpaths
此時可以看到新生成了一個centos:test的p_w_picpath
7.從文件導入容器快照文件,名稱爲centos7:test
本地文件導入:
#cat centos:7.tar | docker import - centos7:test
遠程文件導入:
#docker import http://xxx/xx/abc.txz centos7:test
本地目錄導入:
#tar -c . |docker import - centos7:test
#docker p_w_picpaths
8.將創建的p_w_picpath上傳到registry中,假設已經註冊,自己的鏡像倉庫爲ggvylf。
#docker push ggvylf/centos:test
9.保存名爲centos:test的p_w_picpath爲本地文件
#docker save -o centos:test.tar centos:test
或
#docker save centos:test > centos:test.tar
#ll
10.從本地文件中裝載p_w_picpath
#docker load -i centos:test.tar
或
#docker load < centos:test.tar
#docker p_w_picpaths
11.刪除p_w_picpath:
#dcoker rm -f test
#docker rmi centos:7
12.後臺創建container,以及啓動和停止container:
#docker run -i -t -d --name test centos:7 /bin bash
#docker ps
#docker stop test
#docker ps -a
#docker start test
#docker ps
#docker restart test
#docker ps -a
13.進入啓動的container
#docker exec -it test /bin/bash
14.刪除container
#docker stop test
#docker rm test
或
#docker rm -f test
15.容器的端口綁定和查看:
#docker run -itd --name testport -p 3360:3306 -p 8080:80 centos /bin/bash
#docker port testport
3306/tcp -> 0.0.0.0:3306
80/tcp -> 0.0.0.0:8080
#docker inspect testport|grep -i "IPAddress"
#docker inspect testport|grep -i "HostPort"
16 容器互聯並查看互聯:
#sudo docker run -itd --name testlink --link testport:testtolink centos /bin/bash
#sudo docker inspect testlink|grep -i "testtolink"
或
#sudo docker exec -it testlink /bin/bash
root@xxxxxxxx:/#env
或
#sudo docker ps -a (這個有的教程說在names哪裏能看到做好link的CONTNAME1,CONTNAME2,不過我實驗並沒有看到。)
#yum install docker
或
$sudo apt-get install docker.io
#systemctl enable docker
2.從官方registry搜索p_w_picpath
#docker search centos
3.從官方registry下載p_w_picpath
#docker pull centos
4.使用下載好的鏡像在前臺創建一個container的實例。指定容器名稱爲test,併爲其安裝vim。
#docker run -i -t centos --name test /bin/bash
root@xxxxxxxx:/# yum -y install vim
root@xxxxxxxx:/# exit
#
5.使用修改過的container創建一個新的p_w_picpath副本。
#docker commit -a “ggvylf” -m “install vim” test centos:test
6.查看本地的p_w_picpath:
#docker p_w_picpaths
此時可以看到新生成了一個centos:test的p_w_picpath
7.從文件導入容器快照文件,名稱爲centos7:test
本地文件導入:
#cat centos:7.tar | docker import - centos7:test
遠程文件導入:
#docker import http://xxx/xx/abc.txz centos7:test
本地目錄導入:
#tar -c . |docker import - centos7:test
#docker p_w_picpaths
8.將創建的p_w_picpath上傳到registry中,假設已經註冊,自己的鏡像倉庫爲ggvylf。
#docker push ggvylf/centos:test
9.保存名爲centos:test的p_w_picpath爲本地文件
#docker save -o centos:test.tar centos:test
或
#docker save centos:test > centos:test.tar
#ll
10.從本地文件中裝載p_w_picpath
#docker load -i centos:test.tar
或
#docker load < centos:test.tar
#docker p_w_picpaths
11.刪除p_w_picpath:
#dcoker rm -f test
#docker rmi centos:7
12.後臺創建container,以及啓動和停止container:
#docker run -i -t -d --name test centos:7 /bin bash
#docker ps
#docker stop test
#docker ps -a
#docker start test
#docker ps
#docker restart test
#docker ps -a
13.進入啓動的container
#docker exec -it test /bin/bash
14.刪除container
#docker stop test
#docker rm test
或
#docker rm -f test
15.容器的端口綁定和查看:
#docker run -itd --name testport -p 3360:3306 -p 8080:80 centos /bin/bash
#docker port testport
3306/tcp -> 0.0.0.0:3306
80/tcp -> 0.0.0.0:8080
#docker inspect testport|grep -i "IPAddress"
#docker inspect testport|grep -i "HostPort"
16 容器互聯並查看互聯:
#sudo docker run -itd --name testlink --link testport:testtolink centos /bin/bash
#sudo docker inspect testlink|grep -i "testtolink"
或
#sudo docker exec -it testlink /bin/bash
root@xxxxxxxx:/#env
或
#sudo docker ps -a (這個有的教程說在names哪裏能看到做好link的CONTNAME1,CONTNAME2,不過我實驗並沒有看到。)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.