1、安裝docker,不清楚的請(qǐng)到http://www.itdecent.cn/p/28dda99223f8 ?查看具體安裝步驟
2、查看本機(jī)已經(jīng)拉取的鏡像
[root@localhost ~]# docker images
REPOSITORY? ? ? ? ? TAG? ? ? ? ? ? ? ? IMAGE ID? ? ? ? ? ? CREATED? ? ? ? ? ? SIZE
docker.io/nginx? ? 1.13.10? ? ? ? ? ? 7f70b30f2cc6? ? ? ? 12 days ago? ? ? ? 109 MB
docker.io/tomcat? ? 7? ? ? ? ? ? ? ? ? b6002d3fc5ab? ? ? ? 2 weeks ago? ? ? ? 456 MB
docker.io/centos? ? 7? ? ? ? ? ? ? ? ? 2d194b392dd1? ? ? ? 4 weeks ago? ? ? ? 195 MB
3、搜索可安裝的鏡像的版本
# docker search +要搜索的鏡像名稱(chēng)
[root@localhost ~]# docker search centos
INDEX? ? ? NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DESCRIPTION? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? STARS? ? OFFICIAL? AUTOMATED
docker.io? docker.io/centos? ? ? ? ? ? ? ? ? ? ? ? ? ? The official build of CentOS. ? ? ? ? ? ? ?4153? ? ? [OK] ? ??
......
4、鏡像拉取
[root@localhost ~]# docker pull tomcat:7
Trying to pull repository docker.io/library/tomcat ...
7: Pulling from docker.io/library/tomcat
......
Digest: sha256:6337eea67b0ce5c4ab991037f1de5a5046b46804b28b6cec2c7941595b1b1f63
Status: Downloaded newer image for docker.io/tomcat:7
5、鏡像導(dǎo)出和導(dǎo)入建議查看?http://www.itdecent.cn/p/8408e06b7273,寫(xiě)的還是挺詳細(xì)的
6、啟動(dòng)一個(gè)tomcat鏡像
啟動(dòng)tomcat實(shí)例:
[root@localhost ~]# docker run -d --name my-tomcat7 -p 8888:8080 b6002d3fc5ab
949433da208e7676b9e0a07b50af4436dc0b648b665867225d17876e998add3d
啟動(dòng)命令說(shuō)明:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
OPTIONS說(shuō)明:
-a stdin:?指定標(biāo)準(zhǔn)輸入輸出內(nèi)容類(lèi)型,可選 STDIN/STDOUT/STDERR 三項(xiàng);
-d:?后臺(tái)運(yùn)行容器,并返回容器ID;
-i:?以交互模式運(yùn)行容器,通常與 -t 同時(shí)使用;
-t:?為容器重新分配一個(gè)偽輸入終端,通常與 -i 同時(shí)使用;
--name="nginx-lb":?為容器指定一個(gè)名稱(chēng);
--dns 8.8.8.8:?指定容器使用的DNS服務(wù)器,默認(rèn)和宿主一致;
--dns-search example.com:?指定容器DNS搜索域名,默認(rèn)和宿主一致;
-h "mars":?指定容器的hostname;
-e username="ritchie":?設(shè)置環(huán)境變量;
--env-file=[]:?從指定文件讀入環(huán)境變量;
--cpuset="0-2" or --cpuset="0,1,2":?綁定容器到指定CPU運(yùn)行;
-m :設(shè)置容器使用內(nèi)存最大值;
--net="bridge":?指定容器的網(wǎng)絡(luò)連接類(lèi)型,支持 bridge/host/none/container:?四種類(lèi)型;
--link=[]:?添加鏈接到另一個(gè)容器;
--expose=[]:?開(kāi)放一個(gè)端口或一組端口;
實(shí)例
使用docker鏡像nginx:latest以后臺(tái)模式啟動(dòng)一個(gè)容器,并將容器命名為mynginx。
docker run --name mynginx -d nginx:latest
使用鏡像nginx:latest以后臺(tái)模式啟動(dòng)一個(gè)容器,并將容器的80端口映射到主機(jī)隨機(jī)端口。
docker run -P -d nginx:latest
使用鏡像nginx:latest以后臺(tái)模式啟動(dòng)一個(gè)容器,將容器的80端口映射到主機(jī)的80端口,主機(jī)的目錄/data映射到容器的/data。
docker run -p 80:80 -v /data:/data -d nginx:latest
使用鏡像nginx:latest以交互模式啟動(dòng)一個(gè)容器,在容器內(nèi)執(zhí)行/bin/bash命令。
runoob@runoob:~$ docker run -it nginx:latest /bin/bash
root@b8573233d675:/#
7、部署web應(yīng)用
查看tomcat 安裝目錄
[root@localhost ~]# docker exec -it my-tomcat7 /bin/bash
root@949433da208e:/usr/local/tomcat# ls
LICENSE? NOTICE? RELEASE-NOTES RUNNING.txt? bin? conf include? lib? logs? native-jni-lib? temp? webapps? work
root@949433da208e:/usr/local/tomcat# exit
exit
[root@localhost ~]#
將打包好的war文件導(dǎo)入,查詢(xún)文件位置
[root@localhost ~]# ls
anaconda-ks.cfg? Desktop? Documents? Downloads? Music? Pictures? Public? Templates? Videos? wolfe.war? work
將war包導(dǎo)入容器的webapps目錄中
[root@localhost ~]# docker cp wolfe.war my-tomcat7:/usr/local/tomcat/webapps
[root@localhost ~]#
回車(chē)點(diǎn)擊后,之后瀏覽器中輸入相應(yīng)的htpp地址即可訪(fǎng)問(wèn)部署好的項(xiàng)目
寫(xiě)的有些簡(jiǎn)陋請(qǐng)多多包含。。。。。