• 在Docker中容器是基於鏡像啓動的
• 鏡像是啓動容器的核心
• 鏡像採用分層設計
• 使用快照的COW技術,確保底層數據不丟失mysql
• https://hub.docker.com
• Docker官方提供公共鏡像的倉庫(Registry)linux
• 容器技術已經成爲應用程序封裝和交付的核心技術
• 容器技術的核心有如下幾個內核技術組成:
– CGroups(Control Groups)-資源管理
– NameSpace-進程隔離
– SELinux安全
• 因爲是在物理機上實施隔離,啓動一個容器,能夠像啓動一個進程同樣快速nginx
• Docker是完整的一套容器管理系統
• Docker提供了一組命令,讓用戶更加方便直接地使用容器技術,而不須要過多關心底層內核技術sql
• 相比於傳統的虛擬化技術,容器更加簡潔高效
• 傳統虛擬機須要給每一個VM安裝操做系統
• 容器使用的共享公共庫和程序docker
• 容器的隔離性沒有虛擬化強
• 共用Linux內核,安全性有先天缺陷
• SELinux難以駕馭
• 監控容器和容器排錯是挑戰ubuntu
• 安裝docker平臺所須要的軟件:
– docker-engine
– docker-engine-selinux
– 關閉防火牆vim
CentOS6
[root@localhost ~]# vim /etc/yum.repos.d/docker.repo centos
[dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/6 #baseurl=https://yum.dockerproject.org/repo/main/centos/7 enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg
[root@localhost ~]# yum -y install docker-engine安全
CentOS7
[root@localhost ~]# vim /etc/yum.repos.d/docker.repobash
[dockerrepo] name=Docker Repository #baseurl=https://yum.dockerproject.org/repo/main/centos/6 baseurl=https://yum.dockerproject.org/repo/main/centos/7 enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg
[root@localhost ~]# yum install docker-engine docker-engine-selinux
設置開機啓動
systemctl enable docker
systemctl start docker
系統剛剛配置完是沒有鏡像的
docker images
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker search busybox
[root@localhost ~]# docker search busybox NAME DESCRIPTION STARS OFFICIAL AUTOMATED busybox Busybox base image. 1168 [OK] progrium/busybox 66 [OK] hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with ... 39 radial/busyboxplus Full-chain, Internet enabled, busybox made... 17 [OK] hypriot/armhf-busybox Busybox base image for ARM. 8 armhf/busybox Busybox base image. 4 arm32v7/busybox Busybox base image. 3 prom/busybox Prometheus Busybox Docker base images 2 [OK] armel/busybox Busybox base image. 2 s390x/busybox Busybox base image. 2 onsi/grace-busybox 2 p7ppc64/busybox Busybox base image for ppc64. 2 aarch64/busybox Busybox base image. 2 arm32v6/busybox Busybox base image. 1 spotify/busybox Spotify fork of https://hub.docker.com/_/b... 1 ppc64le/busybox Busybox base image. 1 i386/busybox Busybox base image. 1 concourse/busyboxplus 0 cfgarden/garden-busybox 0 trollin/busybox 0 yauritux/busybox-curl Busybox with CURL 0 ggtools/busybox-ubuntu Busybox ubuntu version with extra goodies 0 [OK] amd64/busybox Busybox base image. 0 ddn0/busybox fork of official busybox 0 [OK] arm64v8/busybox Busybox base image. 0
docker pull busybox
[root@localhost ~]# docker pull busybox latest: Pulling from busybox 97d69bba9a9d: Pull complete 789355058656: Pull complete Digest: sha256:e3789c406237e25d6139035a17981be5f1ccdae9c392d1623a02d31621a12bcc Status: Downloaded newer image for busybox:latest
docker push busybox
• 下載鏡像(從鏡像倉庫中下載鏡像)
[root@localhost ~]# docker pull centos
• 上傳鏡像(上傳鏡像到倉庫)
[root@localhost ~]# docker push centos
• 導入鏡像(經過本地tar包文件導入鏡像)
[root@localhost ~]# docker load < nginx.tar
[root@localhost ~]# docker load < mysql.tar
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos latest 358bf47a7a64 3 weeks ago 203.5 MB busybox latest 789355058656 7 weeks ago 1.129 MB mysql latest 82960a1161e0 14 months ago 383.4 MB nginx latest affde4c9c317 14 months ago 181.4 MB
• 導出鏡像(將本地鏡像導出爲tar文件)
[root@localhost ~]# docker images
[root@localhost ~]# docker save mysql > mysql-im.tar
• 啓動centos鏡像生成一個容器
[root@localhost ~]# docker images
[root@localhost ~]# docker run -it nginx bash
• 開啓另外一個終端(查看容器信息)
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cd7551f2f4ad nginx "bash" 41 seconds ago Up 40 seconds 80/tcp, 443/tcp cranky_hoover [root@localhost ~]#