• 在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 ~]#