根据官网步骤:
官网地址:https://docs.docker.com
1.卸载旧版本的docker配置
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.环境安装包
$ sudo yum install -y yum-utils
3.设置环境的仓库
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo(国外的,比较慢)
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(国内的,比较快推荐使用)
4.安装docker相关内容
安装前最好更新下yum软件索引
yum makecache fast
docker -ce 代表社区版的推荐使用,docker -ee 企业版的
yum install docker-ce docker-ce-cli containerd.io
5.测试启动
systemctl start docker
查看安装版本
docker version
6.运行hellowork镜像
docker run hello-world
安装成功:
7.查看helloword 的镜像
docker images
了解:若是要卸载
分别执行一下命令移除即可
卸载依赖and 删除资源:
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
1.登录阿里云找到容器服务
配置使用:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://25szgwmc.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
配置完毕!!!
回顾:
docker run 镜像名 的原理:
1.帮助命令
docker version #docker 的版本信息
docker info #docker 的系统信息,包括镜像,容器的数量
docker --help #docker 的帮助命令
docker官网的命令:
https://docs.docker.com/engine/reference
2.镜像命令
docker images 查看主机上的所有镜像
docker search 搜索镜像
docker pull 下载镜像
下载默认使用新版: docker pull mysql
docker rmi --删除镜像
3.容器命令
docker pull centos – 再docker容器里面安装小型的centos的服务器(套娃)
docker run -it centos /bin/bash – 运行并进去容器内部的bin/bash目录
容器不退出运行,查看运行的情况
Ctrl+P+Q
删除容器:
常用的其他命令
查看当前容器运行的进程信息
查看镜像的元数据:
#命令
docker inspect 714c594e1748
[root@tianqinhuafirstecs /]# docker inspect 714c594e1748
[
{
“Id”: “714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd”,
“Created”: “2021-04-18T13:02:27.148142235Z”,
“Path”: “/bin/sh”,
“Args”: [
“-c”,
“while true;do echo tianqinhua sleep 100;done”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 20863,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2021-04-18T13:02:27.531686409Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55”,
“ResolvConfPath”: “/var/lib/docker/containers/714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd/hostname”,
“HostsPath”: “/var/lib/docker/containers/714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd/hosts”,
“LogPath”: “/var/lib/docker/containers/714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd/714c594e17487ada1024e6ed3da802d71d821cc6b6927e11bb9c4567cef408bd-json.log”,
“Name”: “/elastic_varahamihira”,
“RestartCount”: 0,
“Driver”: “overlay2”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“CgroupnsMode”: “host”,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “private”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: [],
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DeviceCgroupRules”: null,
“DeviceRequests”: null,
“KernelMemory”: 0,
“KernelMemoryTCP”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: null,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0,
“MaskedPaths”: [
“/proc/asound”,
“/proc/acpi”,
“/proc/kcore”,
“/proc/keys”,
“/proc/latency_stats”,
“/proc/timer_list”,
“/proc/timer_stats”,
“/proc/sched_debug”,
“/proc/scsi”,
“/sys/firmware”
],
“ReadonlyPaths”: [
“/proc/bus”,
“/proc/fs”,
“/proc/irq”,
“/proc/sys”,
“/proc/sysrq-trigger”
]
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/a709c3503ecfea8f6e5660c8b9d55741c80e9deda6f3f5ec29790cab456c92ba-init/diff:/var/lib/docker/overlay2/cb10b343a94489ecbf43edbd225374d2b838d0e689b5de991c94ca59ff71246c/diff”,
“MergedDir”: “/var/lib/docker/overlay2/a709c3503ecfea8f6e5660c8b9d55741c80e9deda6f3f5ec29790cab456c92ba/merged”,
“UpperDir”: “/var/lib/docker/overlay2/a709c3503ecfea8f6e5660c8b9d55741c80e9deda6f3f5ec29790cab456c92ba/diff”,
“WorkDir”: “/var/lib/docker/overlay2/a709c3503ecfea8f6e5660c8b9d55741c80e9deda6f3f5ec29790cab456c92ba/work”
},
“Name”: “overlay2”
},
“Mounts”: [],
“Config”: {
“Hostname”: “714c594e1748”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/sh”,
“-c”,
“while true;do echo tianqinhua sleep 100;done”
],
“Image”: “centos”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“org.label-schema.build-date”: “20201204”,
“org.label-schema.license”: “GPLv2”,
“org.label-schema.name”: “CentOS Base Image”,
“org.label-schema.schema-version”: “1.0”,
“org.label-schema.vendor”: “CentOS”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “a4eb972757d9b2daca37e748a115ab622bfb0d799a1cc1fdaba3fa1793e0617a”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {},
“SandboxKey”: “/var/run/docker/netns/a4eb972757d9”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “231124bc09d99d7014f7307a528ecd67cbb6ef80bd7dd91b162a6f7a162b4bfb”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “7e86895ef17e6aaf6dd8983265ee9072e7b33469c25c27f9b967da33207a634b”,
“EndpointID”: “231124bc09d99d7014f7307a528ecd67cbb6ef80bd7dd91b162a6f7a162b4bfb”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”,
“DriverOpts”: null
}
}
}
}
]
进入当前正在运行的容
将容器内的文件拷贝到主机
命令:
docker cp e91e6e6e2db7:/home/test.java /home
小结:
1.查找nginx镜像:
docker search nginx
2.下载镜像安装
docker pull nginx
3.启动并本机自测:
命令:docker run -d --name nginx03 -p 3344:80 nginx
-d :后台运行
–name:给启动的容器命名,可以启动多个容器分别命名
-p:给启动的nginx暴露端口; -p: 宿主机端口:容器内部端口
对应暴露端口原理关系:
要开放阿里的安全组端口:
内部网络访问:
外部访问测试:
docker官方文档查询:docker hub
$ docker run -it --rm tomcat:9.0
**这个命令一般用来测试,–rm用完即删
查看:docker ps -a 发现并没有记录,说明用完后即删了
#正式自己下载:
docker pull tomcat:9.0
下载成功启动运行容器
docker run -d --name tomcat01 -p 3355:8080 tomcat
#测试启动没问题,但是进入容器发现问题:
1.一些linux不完整;
2.webapps没有内是空的
原因:
阿里云镜像的原因:
默认提供的是最小镜像;保证最小可运行的环境;
#将wepapps.dist下的文件都拷贝到webapps的目录下
拷贝完成后在此访问tomcat 发现:
外网访问都是可以的:
不需要进入容器,在容器外部提供一个映射路径,webapps,在外部放置项目后,能够自动同步到容器内部?
部署es安装相关了解
#es 暴露的端口多
#es 十分耗内存
#es 的数据一般安置在安全的目录!挂载!
#首先查看下Docker hub 官网的elasticsearch
#启动es
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
#启动后linux服务器非常卡,因为es真的很大
#查看cpu的状态
docker stats
#关闭es,增加内存限制,修改配置文件,-e:环境配置修改
docker run -d --name elasticsearch04 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
增加内存先之后查看状态,发现内存限制起作用了
#kibana怎么链接es?
可视化
#portainer(暂时先用这个可视化面板),之后使用:Rancher(CI/CD)
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
#访问测试
#设置密码后选择 Local
#从可视化面板中可以看到,运行中的容器和已停止的容器,都可以可视化执行
当前只是运行两个容器,接下来用可视化启动nginx01