docker的安装:
-
docker的官网地址
-
必须是Centos7版本,最好是7.7的内核,docker目前不支持Centos8
docker源路径的寻找:
-
因为官网的Docker的repo源是通过走国外的网站来获取的,对于网络不是很好的,建议使用阿里镜像站,进入阿里的镜像站,找到docker-ce版本,在官网还有docker-ee版本,是企业版,会收费
-
点击docker_server的安装,里面有安装docker的步骤,按照官方文档操作进行安装就行
-
推荐下载以后学习中用到的镜像
-
使用docker pull命令下载镜像
docker pull centos # 演示生产环境迁移或者安装软件时使用,默认下载完是8版本
docker pull busybox # 工具集,使用centos需要用到
docker pull httpd # apache
docker pull centos # 演示生产环境迁移或者安装软件时使用,默认下载完是8版本
docker pull busybox # 工具集,使用centos需要用到
docker pull httpd # apache
[root@localhost] docker run -it centos
[root@d280c874ea80 /]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
[root@d280c874ea80 /]# exit
可以这里的centos是8版本,所以要将这个镜像删除,由于刚才是先使用镜像运行了容器,i才看到的版本号,容器占用了镜像在运行,所以要先将运行的容器关闭或者删除,删除需要知道刚才运行容器的容器ID
docker ps -a # 查看运行容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
faf96581cf3f centos “/bin/bash” 10 seconds ago Exited (0) 3 seconds ago recursing_goldstine
docker rm faf96581cf3f # 停止容器运行
删除镜像
删除centos:latest的最新版本
docker rmi centos:latest # 删除最新版本
docker pull centos:7 # 下载centos7版本
更改标签
docker tag centos:7 centos:latest
docker rmi centos:7
可以使用上面的方法去查看centos的版本,已经变为7.7,或者直接查看
docker run centos cat /etc/redhat-release
docker的镜像加速
即使使用了阿里云的镜像站,但是拿取的镜像还是走国外的网站,通过命令docker info可以看到
[root@192 ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 2
Server Version: 19.03.8
Storage Driver: overlay2
Backing Filesystem: <unknown>
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 974.6MiB
Name: 192.168.1.6
ID: JZ5Z:EWGC:XMEA:VEVX:MR7N:ACYZ:PPVD:GAWU:HURX:7PZ4:YLKE:O47S
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/ # 这就是国内镜像站镜像所在的仓库地址,还是docker的网站
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
国内镜像加速站
-
我们可以将镜像站改到国内的镜像站,这里国内有两个非常好用的镜像加速服务
-
Daocloud: 市面上比较大的公司,注册登录后,在用户页面点击加速器的标志,加速器链接
-
注册登录后,在用户页面点击加速器的标志
Registry Mirrors:
http://f1361db2.m.daocloud.io/
-
图中部分就是我们要添加到docker配置文件中的内容,会自动生成,如果直接修改daemon.json配置文件,就复制加速器地址就可以,如果是还没有daemon.json,就复制以下配置加速器的命令即可完成阿里云镜像的加速
Registry Mirrors:
https://xxxxxx.mirror.aliyuncs.com/
镜像概念
指计算机中默认的镜像,每个用户都可以进行修改,docker pull后的镜像没有在物理机,需要单独保存到物理机
docker save -o 保存后的路径以及名字 要保存的镜像名:标签
举例:docker save -o centos.tar centos:latest
docker监听
-
该已经发现了,启动docker后,使用netstat -anpt | grep docker并没有监听地址,但是查看启动进程ps -ef | grep docker是没有问题的,现在希望docker变成一个有监听进程的服务
vim /usr/lib/systemd/system/docker.service
在service模块找到14行修改为以下添加了-H tcp://0.0.0.0
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0 --containerd=/run/containerd/containerd.sock
重新加载配置文件并且重启服务
systemctl daemon-reload
systemctl restart docker
再次查看端口 ##2375就是docker的端口
netstat -anpt | grep docker
tcp6 0 0 :::2375 :::* LISTEN 60630/dockerd