Docker安裝與部署
阿新 • • 發佈:2018-11-19
環境部署:
物理機Redhat7.3
一、Docker安裝
1、物理機安裝docker軟體(查詢已安裝的docker軟體)
[[email protected] ~]# rpm -qa | grep docker
docker-engine-selinux-17.03.1.ce-1.el7.centos.noarch
docker-engine-17.03.1.ce-1.el7.centos.x86_64
[[email protected] ~]# systemctl start docker.service
2、載入映象
[[email protected] ~]# cd images/
[[email protected] images]# ls
game2048.tar nginx.tar rhel7.tar
[[email protected] images]# docker load -i game2048.tar
[[email protected] images]# docker load -i nginx.tar
[[email protected] images]# docker load -i rhel7.tar
3、檢視載入的game2048映象
[[email protected] images]# docker images game2048
REPOSITORY TAG IMAGE ID CREATED SIZE
game2048 latest 19299002fdbe 22 months ago 55.5 MB
4、使用docker映象game2048以後臺模式啟動一個容器,並將容器命名為 vm1
[[email protected] images]# docker run -d --name vm1 game2048
6045ae93f9bf93110e014ac0641ce723a764959f44a73d0632c54b28b3b50e77
[ [email protected] images]# docker ps ##列出執行中的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6045ae93f9bf game2048 "/bin/sh -c 'sed -..." 17 seconds ago Up 15 seconds 80/tcp, 443/tcp vm1
[[email protected] images]# docker ps -a ##顯示所有容器(包括未執行容器)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6045ae93f9bf game2048 "/bin/sh -c 'sed -..." 15 minutes ago Up 15 minutes 80/tcp, 443/tcp vm1
- ip addr檢視docker
- brctl show
- ping
5、 獲取容器/映象的元資料
[[email protected] images]# docker inspect vm1
6、測試:訪問172.17.0.2—>game2048小遊戲介面
二、docker埠對映
繫結容器的 8080 埠,並將其對映到本地主機的 80 埠上。
[[email protected] images]# docker stop vm1
[[email protected] images]# docker rm vm1
[[email protected] images]# docker run -d --name vm1 -p 8080:80 game2048
-
列出 nat 表所有鏈的所有規則
-
訪問172.25.51.250:8080
三、docker互動容器
[[email protected] ~]# docker run -it --name vm2 rhel7 bash ##用bash開啟互動介面
bash-4.2# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
bash-4.2# date
Sun Nov 11 09:00:05 EST 2018
bash-4.2# pwd
/
此處 ‘ctrl+p+q’暫時退出bash(打入後臺), ‘ctrl+d’終止bash
[[email protected] ~]# docker attach vm2 ##繼續進入後臺(連線容器)
四、docker加速器
[[email protected] ~]# vim /etc/docker/daemon.json
[[email protected] ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://yuydim8d.mirror.aliyuncs.com"] ##阿里雲加速器地址
}
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart docker.service
- 測試:查詢nginx相關的映象,發現即可下載
注意:阿里雲加速器地址的獲取
五、匯出映象
[[email protected] pub]# docker save ubuntu > ubuntu.tar
[[email protected] pub]# ls | grep ubuntu
ubuntu.tar