Docker CentOS7的系统上安装部署以及基础教程

(编辑:jimmy 日期: 2024/12/29 浏览:2)

说明:

本文介绍如何在CentOS7的系统上安装部署Docker环境,本文参考Docker官方文档如下链接:

https://docs.docker.com/engine/installation/centos/

CentOS7的系统上安装部署Docker环境

1 CentOS7安装(略)

2 升级系统

yum update

升级完成后需要重启下系统。

3 添加docker yum源

执行如下命令:

cat >/etc/yum.repos.d/docker.repo
name=Docker
Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

4 安装Docker软件包

yum install docker-engine

5 启动Docker服务

service docker start

6 测试运行下hello-world镜像

docker run hello-world

7 查看docker信息

使用docker info 命令可以参考系统、Docker的详细信息:

docker info
Containers: 3
Images: 2
Server Version: 1.9.0
Storage Driver: devicemapper
Pool Name: docker-253:0-202597120-pool
Pool Blocksize: 65.54 kB
Base Device Size: 107.4 GB
Backing Filesystem: xfs
Data file: /dev/loop2
Metadata file: /dev/loop3
Data Space Used: 1.824 GB
Data Space Total: 107.4 GB
Data Space Available: 47.87 GB
Metadata Space Used: 1.655 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.146 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.93-RHEL7 (2015-01-28)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-229.20.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 24
Total Memory: 11.57 GiB
Name: localhost.localdomain
ID: VIAJ:MW46:FVFJ:QN7G:XI66:OUBO:M65B:KAUE:BIPC:LL5D:HBCL:762N

8 创建docker用户组,并将用户放到docker组内部

建议使用非root用户运行docker,因为root用户运行docker镜像非常不安全。

创建test1用户,并将用户加入到docker用户组:

[[email protected]~]# useradd test1
[[email protected]~]# usermod -aG docker test1

切到test1用户,运行docker镜像:

[[email protected]~]# su test1
[[email protected]]$
[[email protected]]$ docker run hello-world

9 设置dock服务开机启动

chkconfig docker on

10 卸载Docker

yum list installed | grep docker
yum -y remove docker-engine.x86_64
rm -rf /var/lib/docker

然后删除相关用户。

补充说明:

关于Docker的网络

和kvm类似,看起来也是使用网桥的方式:

[[email protected] ~]# ifconfig
docker0: flags=4163 mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:84ff:fe7f:4510 prefixlen 64 scopeid 0x20
ether 02:42:84:7f:45:10 txqueuelen 0 (Ethernet)
RX packets 12 bytes 840 (840.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3 bytes 258 (258.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 20530318 bytes 1812359321 (1.6 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20530318 bytes 1812359321 (1.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth9422d62: flags=4163 mtu 1500
inet6 fe80::6c36:d0ff:fef5:3996 prefixlen 64 scopeid 0x20
ether 6e:36:d0:f5:39:96 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 828 (828.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242847f4510 no veth9422d62
[[email protected] ~]#

感谢阅读,希望能帮助到大家,谢谢对本站的支持!

一句话新闻

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。