1 前言
Docker 是一个开源的应用容器引擎,是一个用于开发、交付和运行应用程序的开放平台。Docker 可以让使用者打包应用到容器中,发布到 Linux 系统上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不互相干扰,更重要的是容器性能开销极低。
2 docker环境安装与配置
我这里选择centos7系统进行安装
(1)查看系统的内核版本号,建议版本号是在3.10以上
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
(2)先安装yum-utils,yum-utils提供yum-config-manager功能,以及安装依赖文件
yum install -y yum-utils device-mapper-persistent-data lvm2
(3)在yum.中新增docker-ce.repo,设置yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(4)查看docker可安装列表
yum list docker-ce --showduplicates|sort -r
(5)选择一个特定的docker版本进行安装
[root@localhost ~]# yum install docker-ce-17.12.1.ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:17.06.0.ce-1.el7.centos will be updated
---> Package docker-ce.x86_64 0:17.12.1.ce-1.el7.centos will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================
Package Arch Version Repository Size
=========================================================================================
Updating:
docker-ce x86_64 17.12.1.ce-1.el7.centos docker-ce-stable 30 M
Transaction Summary
=========================================================================================
Upgrade 1 Package
Total download size: 30 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
docker-ce-17.12.1.ce-1.el7.centos.x86_64.rpm | 30 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : docker-ce-17.12.1.ce-1.el7.centos.x86_64 1/2
Cleanup : docker-ce-17.06.0.ce-1.el7.centos.x86_64 2/2
Verifying : docker-ce-17.12.1.ce-1.el7.centos.x86_64 1/2
Verifying : docker-ce-17.06.0.ce-1.el7.centos.x86_64 2/2
Updated:
docker-ce.x86_64 0:17.12.1.ce-1.el7.centos
Complete!
(6)开启docker
[root@localhost ~]# systemctl start docker
(7)查看docker版本号
[root@localhost ~]# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
3 docker容器的使用
(1)查看docker的使用参数
(2)可以通过具体命令更深入查看使用方法
(3)获取镜像
[root@localhost /]#docker pull centos
(4)启动获取的镜像容器
参数说明:
- -i: 交互式操作。
- -t: 终端。
- centos: centos 镜像。
- /bin/bash: /bin/bash,通过终端shell的方式进行操作。
(5)查看所有运行或停止的容器
[root@localhost /]# docker ps -a
(6)开启/停止的容器
[root@localhost /]# docker start/stop 79d25ebaa99d
(7)进入容器的方式
第一种:attach方式
[root@localhost /]# docker attach 79d25ebaa99d
第二种:docker exec方式
[root@localhost /]# docker exec -it 79d25ebaa99d /bin/bash
这里如果使用exit退出的话,不会真正退出容器,容器还会在后台运行
(8)退出容器exit
[root@79d25ebaa99d /]# exit
(9)删除一个或多个容器
[root@localhost /]# docker rm -f 9d118729d617 e80f84c30961
欢迎关注「技术分享交流」公众号 ,如果有建议或者疑问的话,欢迎大家评论留言!