欢迎来到CloudService文涵的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

三、Docker常用命令

Docker常用命令

帮助命令

docker version	# 显示 Docker 版本信息。
docker info		# 显示 Docker 系统信息,包括镜像和容器数量
docker --help	# 帮助

镜像命令

docker images

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB

#解释
REPOSITORY     镜像的仓库源
TAG		       镜像的标签
IMAGE ID       镜像的ID
CREATED        镜像创建的时间
SIZE           镜像的大小

#可选项
-a, --all             #列出所有的镜像
-q, --quiet           #只显示镜像的ID

docker search 搜索镜像

[root@localhost ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11895     [OK]       
mariadb                           MariaDB Server is a high performing open sou…   4552      [OK]   


#可选项,通过搜索来过滤
--filter=STARS=3000   #搜索出来的镜像就是STARS大于3000的

[root@localhost ~]# docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   11900     [OK]       
mariadb   MariaDB Server is a high performing open sou…   4552      [OK]      

docker pull 下载镜像

#下载镜像  docker pull 镜像名
[root@localhost ~]# docker pull 镜像名:[tag]
Using default tag: latest     #如果不写tag,默认就是latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete   #分层下载,docker image的核心,联合文件系统
93619dbc5b36: Pull complete 
99da31dd6142: Pull complete 
626033c43d70: Pull complete 
37d5d7efb64e: Pull complete 
ac563158d721: Pull complete 
d2ba16033dad: Pull complete 
688ba7d5c01a: Pull complete 
00e060b6d11d: Pull complete 
1c04857f594f: Pull complete 
4d7cfa90e6ea: Pull complete 
e0431212d27d: Pull complete 
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709    #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest    #真实地址

#等价于它
docker pull mysql
docker pull docker.io/library/mysql:latest

#指定版本下载
[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists 
93619dbc5b36: Already exists 
99da31dd6142: Already exists 
626033c43d70: Already exists 
37d5d7efb64e: Already exists 
ac563158d721: Already exists 
d2ba16033dad: Already exists 
0ceb82207cd7: Pull complete 
37f2405cae96: Pull complete 
e2482e017e53: Pull complete 
70deed891d42: Pull complete 
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

#查看下载后的镜像
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         5.7       c20987f18b13   12 days ago    448MB
mysql         latest    3218b38490ce   12 days ago    516MB
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB

docker rmi 删除镜像

[root@localhost ~]# docker rmi -f 镜像ID	   #删除指定的镜像
[root@localhost ~]# docker rmi -f 镜像ID 镜像ID 镜像ID   #删除多个镜像
[root@localhost ~]# docker rmi -f $(docker images -qa) #删除全部镜像

容器命令

说明∶我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习

docker  pull centos

新建容器并启动

# 命令
docker run [OPTIONS] IMAGE [COMMAND][ARG...]

# 常用参数说明
--name="Name"	# 给容器指定一个名字
-d	# 后台方式运行容器,并返回容器的id!
-i	# 以交互模式运行容器,通过和 -t 一起使用
-t	# 给容器重新分配一个终端,通常和 -i 一起使用
-P	# 随机端口映射(大写)
-p	# 指定端口映射(小结),一般可以有四种写法
	ip:hostPort:containerPort
	ip::containerPort
	hostPort:containerPort (常用)
	containerPort

# 测试
[root@localhost ~]# docker images
REPOSITORY	TAG	IMAGE ID	CREATED
	SIZE
centos	latest	470671670cac	3 months ago
	237MB

# 使用centos进行用交互模式启动容器,在容器内执行/bin/bash命令!
[root@localhost ~]# docker run -it centos /bin/bash
[root@dc8f24dd06d0 /]# ls	# 注意地址,已经切换到容器内部了!
bin etc	lib	lost+found  mnt proc run	srv tmp var
dev  home lib64 media	opt root sbin sys usr
[root@dc8f24dd06d0 /]# exit # 使用 exit 退出容器
exit
[root@kuangshen ~]#

列出所有运行的容器
# 命令
docker ps [OPTIONS]

# 常用参数说明
-a		# 列出当前所有正在运行的容器 + 历史运行过的容器
-l		# 显示最近创建的容器
-n=?	# 显示最近n个创建的容器
-q		# 静默模式,只显示容器编号。

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                          PORTS     NAMES
2d994f054cf3   centos         "/bin/bash"   3 minutes ago   Exited (0) About a minute ago             confident_wozniak
7df2aef6560d   centos         "/bin/bash"   5 minutes ago   Exited (127) 3 minutes ago                eloquent_mclean
23c1d97fcef4   feb5d9fea6a5   "/hello"      4 hours ago     Exited (0) 4 hours ago                    magical_pascal
20206ca7c368   feb5d9fea6a5   "/hello"      4 hours ago     Exited (0) 4 hours ago                    stoic_meninsky

[root@localhost ~]# docker ps -n=1
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
2d994f054cf3   centos    "/bin/bash"   10 minutes ago   Exited (0) 8 minutes ago             confident_wozniak

[root@localhost ~]# docker ps -qa
2d994f054cf3
7df2aef6560d
23c1d97fcef4
20206ca7c368

退出容器

exit   #容器停止并退出
ctrl + P + Q #容器不停止并退出

删除容器

docker rm 容器ID                 #删除指定的容器,不能删除正在运行的容器,如果要强制删除就要用rm -rf     
docker rm -f $(docker ps -qa)   #删除所有容器

启动和停止容器的操作

[root@localhost ~]# docker start 容器id      #启动容器
[root@localhost ~]# docker restart 容器id    #重启容器
[root@localhost ~]# docker stop 容器id       #停止当前正在运行的容器
[root@localhost ~]# docker kill 容器id       #强制停止当前容器

常用其他命令

后台启动命令

#docker  run  -d 镜像名
[root@localhost ~]# docker run -d centos

#问题docker ps,发现centos停止了

#常见的坑:docker容器使用后台运行,就必须要有要一个前台进程,docker发现没有应用,就会自动停止

# nginx,容器启动后,发现自己没有提供服务,就会立刻停止,就是没有程序了

查看日志

docker logs -tf --tail 容器——————没有日志

#自己编写一段shell脚本
[root@localhost ~]# docker run -d centos /bin/sh -c "while true;do echo wenhan;sleep 1; done"

#[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES
95734c88f11d   centos    "/bin/sh -c 'while t…"   2 minutes ago   Up 2 minutes             mystifying_mendeleev
60755c295f3c   centos    "/bin/bash"              23 hours ago    Up 23 hours              trusting_raman

显示日志

-tf                  #显示日志
--tail number        #要显示日志条数
[root@localhost ~]# docker logs -tf --tail 10 1968c24ddd98

查看容器中进程信息ps

#命令 docker top 容器id
[root@localhost ~]# docker top 1968c24ddd98
UID                 PID                 PPID                C                   STIME               TTY     
root                3590                3567                0                   15:44               pts/0              

查看镜像的元数据

#命令  
docker inspect  容器id

#测试
[root@localhost ~]# docker inspect 1968c24ddd98
[
    {
        "Id": "1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179",
        "Created": "2022-01-03T07:43:26.99447412Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 3590,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-01-03T07:44:16.28904696Z",
            "FinishedAt": "2022-01-03T07:43:48.148938081Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179/hostname",
        "HostsPath": "/var/lib/docker/containers/1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179/hosts",
        "LogPath": "/var/lib/docker/containers/1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179/1968c24ddd9892f511dcafdf0bd702a2cbbf088495b5fa4010a819a0986fa179-json.log",
        "Name": "/boring_albattani",
        "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/9eee4d7fb0b5a3ab9f098c0569584f1de34ceb5d6980fd0279c83f09e9708eea-init/diff:/var/lib/docker/overlay2/f6b5213c84dad1930646bcf77ab538539a36cca3689fba20beeafcf8cb6e451c/diff",
                "MergedDir": "/var/lib/docker/overlay2/9eee4d7fb0b5a3ab9f098c0569584f1de34ceb5d6980fd0279c83f09e9708eea/merged",
                "UpperDir": "/var/lib/docker/overlay2/9eee4d7fb0b5a3ab9f098c0569584f1de34ceb5d6980fd0279c83f09e9708eea/diff",
                "WorkDir": "/var/lib/docker/overlay2/9eee4d7fb0b5a3ab9f098c0569584f1de34ceb5d6980fd0279c83f09e9708eea/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "1968c24ddd98",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "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": "08fe910f6d85f9d1a027f8c19f07932095543c6e6fbb9fa0961a80daf10866e1",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/08fe910f6d85",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "47f204951a405b4e5411c919bdcdd7a1c74857ce1d51dd8790bb0239a54c31c9",
            "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": "ab066a4090fda0da01fba8af7ad237190488555a4dadfc5242e361eafd476a8c",
                    "EndpointID": "47f204951a405b4e5411c919bdcdd7a1c74857ce1d51dd8790bb0239a54c31c9",
                    "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 bashshell

#测试
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
1968c24ddd98   centos    "/bin/bash"   19 minutes ago   Up 18 minutes             boring_albattani
[root@localhost ~]# docker exec -it 1968c24ddd98 /bin/bash
[root@1968c24ddd98 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@1968c24ddd98 /]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 07:44 pts/0    00:00:00 /bin/bash
root        15     0  0 08:03 pts/1    00:00:00 /bin/bash
root        30    15  0 08:03 pts/1    00:00:00 ps -ef

#方式二
docker attach 容器id

#测试
[root@localhost ~]# docker attach 1968c24ddd98
正在执行当前的代码......

# docker exec    #进入容器后开启一个新的终端,可以在里面操作(常用)
# docker attach  #进入容器正在执行的终端,不会启动新的进程!

从容器内拷贝文件到主机上

docker cp  容器id:容器内路径    目的的主机路径

#查看当前主机目录下
[root@localhost ~]# cd /home/
[root@localhost home]# ls
admin  www
#查看正在运行的容器
[root@localhost home]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
1968c24ddd98   centos    "/bin/bash"   36 minutes ago   Up 35 minutes             boring_albattani
#进入容器
[root@localhost ~]# docker attach 4f91166e096e
[root@4f91166e096e /]# cd /home/
[root@4f91166e096e home]# ls
#在容器中创建一个文件
[root@4f91166e096e home]# touch wenhan.java
[root@4f91166e096e home]# ls
wenhan.java
[root@4f91166e096e home]# exit
exit
#将这个文件拷贝到主机上
[root@localhost ~]# docker cp 4f91166e096e:/home/wenhan.java /home/
[root@localhost ~]# cd /home/
[root@localhost home]# ls
admin  wenhan.java  www

#拷贝是一个手动过程,未来我们使用-v卷的技术,可以实现

小结

attach		Attach to a running container  #当前she17 下attach连接指定运行镜像
bui1d		Bui1d an image from a Dockerfile  #通过Dockerfile定制镜像
commit  	create a new image from a container changes  #提交当前容器为新的镜像cp
cp			Copy files/folders from the containers filesystem to the host path #从容器中拷贝指定文件或者目录到宿主机中
create  	Create a new container#创建一个新的容器,同run,但不启动容器
diff  		Inspect changes on a container's filesystem  #查看docker容器变化
events  	Get real time events from the server  #从docker服务获取容器实时事件
exec   		Run a command in an existing container  #在已存在的容器上运行命令
export 		Stream the contents of a container as a tar archive#导出容器的内容流作为一个 tar 归档文件[对应import ]
history  	Show the history of an image#展示一个镜像形成历史
images  	List images  #列出系统当前镜像
import  	create a new filesystem image from the contents of a tarball# 从tar包中的内容创建一个新的文件系统映像[对应export]
info 	 	Display system-wide information  #显示系统相关信息
inspect  	Return low-level information on a container  #查看容器详细信息ki11
kill  		Kill a running container  # kill指定docker容器
load  		Load an image from a tar archive  #从一个tar包中加载一个镜像[对应save]
login   	Register or Login to the docker registry server#注册或者登陆一个docker源服务器
logout  	Logout from a Docker registry server  #从当前Docker registry退出
logs  		Fetch the logs of a container  #输出当前容器日志信息
port 		Lookup the public-facing port which is NAT-ed to PRIVATE_PORT #查看映射端口对应的容器内部源端口
pause  		Pause a71 processes within a container  #暂停容器
ps  		List containers  #列出容器列表
pu11  		Pull an image or a repository from the docker registry server# 从docker镜像源服务器拉取指定镜像或者库镜像
push  		Push an image or a repository to the docker registry server # 推送指定镜像或者库镜像至docker源服务器
restart  	Restart a running container  #重启运行的容器
rm  		Remove one or more containers  #移除一个或者多个容器
rmi  		Remove one or more images  #移除一个或多个镜像[无容器使用该镜像才可删除,否则需删除相关容器才可继续或-f强制删除]
run  		Run a command in a new container  #创建一个新的容器并运行一个命令
save  		save an image to a tar archive  #保存一个镜像为一个 tar包[对应1oad]
search  	search for an[image on the Docker Hub  #在docker hub中搜索镜像
start  		Start a stopped containers  #启动容器
stop  		stop a running containers  #停止容器
tag  		Tag an image into a repository  #给源中镜像打标签
top  		Lookup the running processes of a container #查看容器中运行的进程信息
unpause  	Unpause a paused container  #取消暂停容器
version  	Show the docker version information  #查看docker版本号
wait  		Block until a container stops,then print its exit code  #截取容器停止时的退出状态值

作业练习

Docker 安装nginx

#1、搜索镜像   search   建议大家去docker搜索,可以看到帮助文档
#2、下载镜像   pu11
#3、运行测试
[root@localhost ~]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    605c77e624dd   4 days ago     141MB
centos       latest    5d0da3dc9764   3 months ago   231MB

# -d		    后台运行
# --name		给容器命名
# -p			宿主机端口:容器内部端口
[root@localhost ~]# docker run -d --name nginx01 -p 3390:80 nginx
af810b00b03d07b1f7eb72272ff80121dcf6220de8f79c3796aee13a687c6a31
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                  NAMES
af810b00b03d   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:3390->80/tcp   nginx01

#测试
[root@localhost ~]# curl localhost:3390

#进入容器
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    605c77e624dd   4 days ago     141MB
centos       latest    5d0da3dc9764   3 months ago   231MB
[root@localhost ~]# docker run -exec -it nginx /bin/bash
root@fd2ea18bc6b7:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@fd2ea18bc6b7:/# cd /etc/nginx/
root@fd2ea18bc6b7:/etc/nginx# ls
conf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params

使用docker安装 tomcat

# 官方文档解释
# -it :交互模式
# --rm:容器启动成功并退出以后容器就自动移除,一般在测试情况下使用!
docker run -it --rm tomcat:9.0

# 1、下载tomcat镜像
docker pull tomcat

# 2、启动
docker run -d -p 8080:8080 --name tomcat9 tomcat

# 3、进入tomcat
docker exec -it tomcat9 /bin/bash

# 4、思考:我们以后要部署项目,还需要进入容器中,是不是十分麻烦,要是有一种技术,可以将容器
内和我们Linux进行映射挂载就好了?我们后面会将数据卷技术来进行挂载操作,也是一个核心内容,这
里大家先听听名词就好,我们很快就会讲到!

使用docker 部署 es + kibana

1	# 我们启动es这种容器需要考虑几个问题
2	1、端口暴露问题 9200、9300
3	2、数据卷的挂载问题 data、plugins、conf
4	3、吃内存 - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
5	
6	# 扩展命令
7	docker stats 容器id	# 查看容器的cpu内存和网络状态
8	
9	# 1、启动es测试
10	docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e
	"discovery.type=single-node" elasticsearch:7.6.2
11	
12	# 2、启动之后很卡,使用 docker stats 容器id 查看下cpu状态 ,发现占用的很大
13	CONTAINER ID	NAME	CPU %	MEM USAGE /
	LIMIT	MEM %
14	249ae46da625	elasticsearch	0.00%	1.036GiB /
	1.716GiB	60.37%
15	
16	# 3、测试访问
17	[root@kuangshen data]# curl localhost:9200
18	{
19	"name" : "249ae46da625",
20	"cluster_name" : "docker-cluster",
21	"cluster_uuid" : "_Ho_i4fOTUesNc_II35sSA",
22	"version" : {
23	"number" : "7.6.2",
24	"build_flavor" : "default",
25	"build_type" : "docker",
26	"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
27	"build_date" : "2020-03-26T06:34:37.794943Z",
 
28	"build_snapshot" : false,
29	"lucene_version" : "8.4.0",
30	"minimum_wire_compatibility_version" : "6.8.0",
31	"minimum_index_compatibility_version" : "6.0.0-beta1"
32	},
33	"tagline" : "You Know, for Search"
34	}
35	
36	# 4、增加上内存限制启动
37	docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e
	"discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m"
	elasticsearch:7.6.2
38	
39	# 5、启动之后,使用 docker stats 查看下cpu状态
40	CONTAINER ID	NAME	CPU %	MEM USAGE /
	LIMIT	MEM %
41	d2860684e7e4	elasticsearch	0.24%	358.3MiB /
	1.716GiB	20.40%
42	
43	# 6、测试访问,效果一样,ok!
44	[root@kuangshen data]# curl localhost:9200
45	
46	# 思考:如果我们要使用 kibana , 如果配置连接上我们的es呢?网络该如何配置呢?

可视化

Portainer(先用这个)

docker run -d -p 8088:9000 \
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --
privileged=true portainer/portainer

Rancher(CI/CD再用这个)

#安装rancher-server
docker run --name rancher-server -p 8000:8080 -v
/etc/localtime:/etc/localtime:ro -d rancher/server
#安装agent
docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v
/var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11
http://39.101.191.131:8000/v1/scripts/D3DBD43F263109BB881F:1577750400000:7M0y
BzCw4XSxJklD7TpysYIpI

介绍:

Portainer是Docker的图形化管理工具,提供状态显示面板、应用模板快速部署、容器镜像网络数据卷 的基本操作(包括上传下载镜像,创建容器等操作)、事件日志显示、容器控制台操作、Swarm集群和 服务等集中管理和操作、登录用户管理和控制等功能。功能十分全面,基本能满足中小型单位对容器管 理的全部需求。

如果仅有一个docker宿主机,则可使用单机版运行,Portainer单机版运行十分简单,只需要一条语句即 可启动容器,来管理该机器上的docker镜像、容器等数据。

docker run -d -p 8088:9000 \
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --
privileged=true portainer/portainer

访问方式:http://IP:8088

首次登陆需要注册用户,给admin用户设置密码:

单机版这里选择local即可,选择完毕,点击Connect即可连接到本地docker:

登录成功!

我们可以点击可视化界面来玩玩!

posted on 2022-04-06 16:26  Cloudservice  阅读(97)  评论(0编辑  收藏  举报