这篇文章主要为大家分析了Linux上怎么安装和使用Docker的相关知识点,内容详细易懂,操作细节合理,具有一定参考价值。如果感兴趣的话,不妨跟着跟随小编一起来看看,下面跟着小编一起深入学习“Linux上怎么安装和使用Docker”的知识吧。
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。CentOS 7 中 Docker 的安装
Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:
[root@localhost ~]# yum install docker
查看docker版本
[root@localhost ~]# docker versionClient:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: cedd534-dirty
Built: Fri Jan 22 06:07:01 UTC 2016
OS/Arch: linux/amd64
Server:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: cedd534-dirty
Built: Fri Jan 22 06:07:01 UTC 2016
OS/Arch: linux/amd64
显示版本为docker 1.83,API 版本 1.20 。
启动 Docker 服务
安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:
[root@localhost ~]# systemctl start docker.service[root@localhost ~]# systemctl enable docker.service
下载官方的 CentOS 镜像到本地
[root@localhost ~]# docker pull centosPulling repository centos
192178b11d36: Download complete
70441cac1ed5: Download complete
ae0c2d0bdc10: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
确认 CentOS 镜像已经被获取
[root@localhost ~]# docker images centosREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos5 192178b11d36 2 weeks ago 466.9 MB
centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
centos latest ae0c2d0bdc10 2 weeks ago 224 MB
运行一个 Docker 容器
[root@localhost ~]# docker run -i -t centos /bin/bash[root@dbf66395436d /]#
我们可以看到 CentOS 容器已经被启动,并且我们看到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。
若要断开与容器的连接,则输入 exit。
[root@cd05639b3f5c /]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core)
[root@cd05639b3f5c /]# exitexit[root@localhost ~]#
我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器
[root@localhost ~]# docker search ubuntu[root@localhost ~]# docker search fedora
显示当前正在运行容器的列表
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e422481ac1ce daocloud.io/daocloud/dao-2048 "nginx -g 'daemon off" 45 hours ago Up 45 hours 0.0.0.0:32768->80/tcp hungry_visvesvaraya
关于“Linux上怎么安装和使用Docker”就介绍到这了,更多相关内容可以搜索天达云以前的文章,希望能够帮助大家答疑解惑,请多多支持天达云网站!