1、地址
视频地址:https://www.bilibili.com/video/BV1og4y1q7M4?p=6
万能命令【帮助命令】
docker run --help
2、只显示镜像ID
docker images -q
3、搜索下载镜像
docker search mysql
docker pull mysql
4、docker的递归命令
docker rmi -f $(docker images eurka -q)
5、docker容器命令可选项
docker run [ 可选] image
--name 指定容器名字
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-P 指定容器端口
连带执行命令
docker run -d centos /bin/bash -c "echo 'asdf' "
6、docker ps
docker ps 【可选参数】
默认展示正在运行的容器
-a #展示所有容器
-n #只展示最新几条容器
-q #只显示容器ID
7、常用其他命令
后台启动容器
[root@localhohst /]# docker run -d centos
#问题 docker ps 发现容器停止了
#常见坑,docker容器使用后台运行,必须要有一个前台进程,否则,docker发现没有应用的话,就会自动停止
查看日志
docker logs -tf --tail 10 容器
查看进程
docker top 容器ID
查看详细信息
docker inspect 容器ID
{
"Id": "bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e",
"Created": "2021-09-21T00:01:34.670128694Z",
"Path": "bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 17619,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-09-21T00:01:34.855574355Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:219665e0dcb6139dc835be1859467cbb543d1b51759abe7317c1e0a7c3ce76de",
"ResolvConfPath": "/var/lib/docker/containers/bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e/hostname",
"HostsPath": "/var/lib/docker/containers/bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e/hosts",
"LogPath": "/var/lib/docker/containers/bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e/bab2479b83420648b0ef2901d40deb2cc953da17e9a9eba736ec054f8838999e-json.log",
"Name": "/eureka",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8383/tcp": [
{
"HostIp": "",
"HostPort": "8383"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"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,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/4f6acc679a64226007a906eb8eda0b9e770ecf62eb54ab4139d6baef66d7dc60-init/diff:/var/lib/docker/overlay2/8b6dea114bad4652e3a6d698a262f6c0ab578e7d91a6bdf8fe6d49991deb0489/diff:/var/lib/docker/overlay2/3e4a7cd8f878516890e5b9b589965e1babffa2fc9ef5509ef8a376bdc59e0692/diff:/var/lib/docker/overlay2/ffced512403b7695132a855cce965134b6980f514216d0d354149f667eaadb5d/diff:/var/lib/docker/overlay2/0eca75e1d717b5a6d8e16b6c53d75d90bebccb3582da40a865f8a7a1c7ead03c/diff:/var/lib/docker/overlay2/3f0666a3c8bd188c5f3d3bf8d56580e51fb57c16a4cdbc2a1ea12001afedc239/diff:/var/lib/docker/overlay2/9200f17507186c50508ac30e216189069da7547a4142144ac05c0cd511adf2ea/diff:/var/lib/docker/overlay2/043f4485df9066a13d5fa76a4cc60893a9ce330ae58b1f8a4ae3984ab21266b0/diff:/var/lib/docker/overlay2/bb3cf3b35db0498c4e36f401fea22bed581ad147012ea2490752aa182e091820/diff:/var/lib/docker/overlay2/6e776137a76b96e1d81f07121a4e31cef9f4fa5b7a40e678c16551ee9f0cb439/diff",
"MergedDir": "/var/lib/docker/overlay2/4f6acc679a64226007a906eb8eda0b9e770ecf62eb54ab4139d6baef66d7dc60/merged",
"UpperDir": "/var/lib/docker/overlay2/4f6acc679a64226007a906eb8eda0b9e770ecf62eb54ab4139d6baef66d7dc60/diff",
"WorkDir": "/var/lib/docker/overlay2/4f6acc679a64226007a906eb8eda0b9e770ecf62eb54ab4139d6baef66d7dc60/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "bab2479b8342",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"8383/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"JAVA_HOME=/usr/local/openjdk-8",
"LANG=C.UTF-8",
"JAVA_VERSION=8u302"
],
"Cmd": [
"bash"
],
"Image": "eureka:v1",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "fa978429fff48fbd2c36b66940c80c99f18904a6dbae921951c2f7b7e37c0f38",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8383/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8383"
}
]
},
"SandboxKey": "/var/run/docker/netns/fa978429fff4",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "b299bf407ee38cd81ee144b8dfa764c1b8f6603abfc7dc26566cd7715cbdb33b",
"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": "82943f3f2dafdf213c76e9e876e7ed071d84a8a453565980ad7811958bb0f4b6",
"EndpointID": "b299bf407ee38cd81ee144b8dfa764c1b8f6603abfc7dc26566cd7715cbdb33b",
"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 exec -it 容器ID /bin/bash
#进入正在运行的终端
docker attach 容器ID
数据迁移
容器==>宿主机
docker cp bab2479b8342:/home/test.java /home
小结
P14 作业一:部署Nginx
1、搜索镜像 search
2、下载镜像 pull
3、运行测试 run
4、后台运行 -d
5、给容器命名--name
6、开放映射指定端口 -p 外部端口:内部端口
7、进入容器查看日志
P15 部署tomcat
1、官方的使用方式
docker run -it --rm tomcat:9.0
--rm: 停止就会自动删除,可用于临时测试
2、拉取镜像docker pull tomcat
3、docker run -d -p 3355:8080 --name tomcat01 tomcat
4、进入容器 docker exec -it tomcat01 /bin/bash
P16 部署ES+KIBANA
问题:
ES要求暴露端口非常多
ES非常耗内存
ES的数据一般需要放置到安全目录
1、官方命令:启动ES[后面的tag版本号是必要的,否则会报错]
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.14.1
--net somenetwork 网络配置
启动ES以后,因为ES非常消耗内存
查看状态:docker stats
2、检查是否安装成功
curl localhost:9200
3、通过-E增加配置来减少内存消耗
docker run -d --name ES --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.14.1
可视化
portainer
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
rancher(CICD)
portainer
一、什么是portainer?
Docker图形化管理界面工具,提供一个后台面板以供使用
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
二、测试安装
访问:localhost:8088 [docker run的时候指定了外部映射端口]
三、继续
设置完密码,只要选择local模式即可
彻底进入之前会有确认提示:【在docker run的时候就已经设置了卷挂载】
Ensure that you have started the Portainer container with the following Docker flag:
-v "/var/run/docker.sock:/var/run/docker.sock"
(Linux).
P18 P19全是原理,分层堆叠镜像的原理与联合文件系统的简介
镜像层与容器层也是一样的原理,堆叠而成
P20提交镜像【需实战,解决JDK报错问题】
docker commit命令:用于将修改后的容器提交成为新的镜像
docker commit -a="kunags" -m="add webapps app" 容器ID 镜像名称
docker commit -a="dengliang" -m ="test first docker commit" 5d18223548b0 test_first_commit:v1
OPTIONS说明:
-
-a :提交的镜像作者;
-
-c :使用Dockerfile指令来创建镜像;
-
-m :提交时的说明文字;
-
-p :在commit时,将容器暂停。
1、先关掉之前的
docker stop $(docker ps -aqf "name=eureka")
docker rm eureka
2、启动新的
docker run -d --name=test02 -p 8383:8383 test_first_commit:v1
3、进入查看
docker exec -it $(docker ps -aqf "name=test02") /bin/bash
容器数据卷技术
使用数据卷
方式一 直接使用命令挂载 -v
docker run -it -v 主机目录:容器目录
docker run -it -v /home/ceshi:/home/inner
实际使用:
docker run -d --name=eureka -p 8383:8383 -v /home/dengliang/autoDeploy/main_java:/home/main_java eureka:v1
安装Mysql
1、拉取镜像
docker pull mysql:5.7
2、镜像装进容器运行
设置名称、端口映射、数据卷、密码配置以及后台配置
docker run -d --name=mysql -p 3306:3306 -v /home/dengliang/docker/mysql/conf:/etc/mysql/conf.d -v /home/dengliang/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=88888888 mysql:5.7
3、安装phpmyadmin进行数据库链接[废弃,大概率要在说完网络之后才能真正从一个容器访问另外一个容器]
$ docker pull phpmyadmin:5.1
#然后配置启动
$ docker run --name myadmin -d -e PMA_HOST=localhost -e PMA_PORT=3306 -p 8180:80 -v /home/dengliang/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php -v /home/dengliang/phpmyadmin/sessions:/sessions -v /home/dengliang/phpmyadmin//www/themes:/www/themes phpmyadmin
$ docker run --name myadmin -d --link mysql:db -e PMA_HOST=localhost -e PMA_PORT=3306 -p 8180:80
-v /home/dengliang/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php -v /home/dengliang/phpmyadmin/sessions:/sessions -v /home/dengliang/phpmyadmin/www/themes:/www/themes phpmyadmin:5.1
#网络用docker network ls来查看
#一共 bridge host none somenetwork四种
$ docker run --name myadmin -d --link mysql:db -p 8180:80 –net single_default -v /home/dengliang/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php -v /home/dengliang/phpmyadmin/sessions:/sessions -v /home/dengliang/phpmyadmin/www/themes:/www/themes phpmyadmin:5.1
3、利用另外一台电脑链接3306查看数据库
标签:容器,run,记录,--,学习,var,docker,null From: https://www.cnblogs.com/dengliang356a/p/17600495.html