docker专题(一)安装及常用命令
简介
官方地址 :https://docs.docker.com/docker-for-windows/
b站教程:https://www.bilibili.com/video/BV1og4y1q7M4
笔记就是基于该教程
安装
#卸载Docker
# 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
# 删除资源
rm -rf /var/lib/docker # docker 的默认工作路径
# 1.卸载旧的版本
$ 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.设置镜像仓库
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo # 默认是国外的
# 换成下面的
$ sudo yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 阿里云镜
# 更像软件包索引
yum makecache fast
# 4.安装docker引擎
yum install docker-ce docker-ce-cli containerd.io # docker-ce 社区版 ee 企业
#5. 启动Docker
systemctl start docker # 代表启动成功
#查看是否安装成功
#6.hello,world 本地没有,从仓库拉取
docker run hello-world
#7.查看下载的镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 5 weeks ago 13.3kB
Docker命令
帮助命令
# 系统信息,镜像和容器的数量
docker info
#帮助信息
dokcer 命令 --help
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker --help
Usage: docker COMMAND
A self-sufficient runtime for containers
#可选参数
Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to (default [])
-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
#管理命令
Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes
#命令
Commands:
#当前shell下attach连接指定运行镜像
attach Attach to a running container
#通过Dockerfile定制镜像
build Build an image from a Dockerfile
#提交当前容器为镜像
commit Create a new image from a container's changes
#从容器中拷贝指定文件或目录到宿主机上
cp Copy files/folders between a container and the local filesystem
#创建一个新的容器,同run但是不启动容器
create Create a new container
#查看docker容器变化
diff Inspect changes on a container's filesystem
#从docker服务获取容器实时事件
events Get real time events from the server
#在已存在的容器上运行命令
exec Run a command in a running container
#导出容器的内容作为一个tar 归档文件
export Export a container's filesystem as a tar archive
#展示一个容器构建历史
history Show the history of an image
#列出当前系统镜像
images List images
#从tar包中的内容创建一个新的文件系统映像
import Import the contents from a tarball to create a filesystem image
#显示系统相关信息
info Display system-wide information
#查看容器详细信息
inspect Return low-level information on Docker objects
#杀除指定docker容器
kill Kill one or more running containers
#从tar包中加载指定容器
load Load an image from a tar archive or STDIN
#登录docker源服务器
login Log in to a Docker registry
#登出docker源服务器
logout Log out from a Docker registry
#输出当前容器日志信息
logs Fetch the logs of a container
#暂停一个或多个容器内的所有进程
pause Pause all processes within one or more containers
#查看映射端口对应的容器内部端口
port List port mappings or a specific mapping for the container
#列出容器列表
ps List containers
#拉取镜像
pull Pull an image or a repository from a registry
#推送镜像
push Push an image or a repository to a registry
#重命名容器
rename Rename a container
#重启容器
restart Restart one or more containers
#删除容器
rm Remove one or more containers
#删除镜像
rmi Remove one or more images
#创建容器
run Run a command in a new container
#保存一个镜像为tar包
save Save one or more images to a tar archive (streamed to STDOUT by default)
#搜索镜像
search Search the Docker Hub for images
#启动容器
start Start one or more stopped containers
#容器状态
stats Display a live stream of container(s) resource usage statistics
#停止ring器
stop Stop one or more running containers
#打标签
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
#查看容器中运行的进行信息
top Display the running processes of a container
#取消暂停一个或多个容器中的所有进程
unpause Unpause all processes within one or more containers
#更新一个或多个容器的配置
update Update configuration of one or more containers
#查看docker版本信息
version Show the Docker version information
#截取容器停止时的退出状态值
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
命令图解
镜像命令
docker images 镜像
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests#摘要
-f, --filter filter Filter output based on conditions provided
#这个过滤标签的格式是 “key=value”,如果有多个条件,则使用这种 --filter “key1=value” --filter “key2=value”
#当前支持的过滤配置的key为
#dangling:显示标记为空的镜像,值只有true和false
#label:这个是根据标签进行过滤,其中lable的值,是docker在编译的时候配置的或者在Dockerfile中配置的
#before:这个是根据时间来进行过滤,其中before的value表示某个镜像构建时间之前的镜像列表
#since:跟before正好相反,表示的是在某个镜像构建之后构建的镜像
#reference:这个是添加正则进行匹配
--format string Pretty-print images using a Go template
#如docker images --format "{{.ID}}\t{{.Repository}}"
#.ID
#.Repository 仓库
#.Tag 标签
#.Digest 简介
#.CreatedSince 创建
#.CreatedAt
#.Size 大小
--help Print usage
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
docker search 搜索
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
Options:
-f, --filter filter Filter output based on conditions provided
--help Print usage
--limit int Max number of search results (default 25)
--no-index Don't truncate output
--no-trunc Don't truncate output
#查询镜像
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker search netcore
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/casualgamesonline/netcore-build 1
docker.io docker.io/guilhem/netcore DNS and DHCP service written in Go, config... 1 [OK]
docker.io docker.io/stephenlautier/netcore-docker-ci 1
docker.io docker.io/stephenlautier/netcore-docker-spa 1
#查询镜像限制两条
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker search netcore --limit 2
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/ambdock/netcore 0
docker.io docker.io/singireddy/netcoredockerapi 0
#过滤
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker search redis --filter=STARS=9624
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/redis Redis is an open source key-value store th... 9624 [OK]
docker pull 下载镜像
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Options:
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--help Print usage
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker pull mysql
Using default tag: latest#下载mysql镜像 ,默认最新版本
Trying to pull repository docker.io/library/mysql ...
latest: Pulling from docker.io/library/mysql
b4d181a07f80: Pull complete #layer 分层下载 ,dockerimage的核心 联合文件系统
a462b60610f5: Pull complete
578fafb77ab8: Pull complete
524046006037: Pull complete
d0cbe54c8855: Pull complete
aa18e05cc46d: Pull complete
32ca814c833f: Pull complete
9ecc8abdb7f5: Pull complete
ad042b682e0f: Pull complete
71d327c6bb78: Pull complete
165d1d10a3fa: Pull complete
2f40c47d0626: Pull complete
Digest: sha256:52b8406e4c32b8cf0557f1b74517e14c5393aff5cf0384eff62d9e81f4985d4b
Status: Downloaded newer image for docker.io/mysql:latest #真实地址
#指定版本下载
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
b4d181a07f80: Already exists #Already exist 与上面拉取的mysql公用的部分就不再拉取
a462b60610f5: Already exists
578fafb77ab8: Already exists
524046006037: Already exists
d0cbe54c8855: Already exists
aa18e05cc46d: Already exists
32ca814c833f: Already exists
52645b4af634: Pull complete
bca6a5b14385: Pull complete
309f36297c75: Pull complete
7d75cacde0f8: Pull complete
Digest: sha256:1a2f9cd257e75cc80e9118b303d1648366bc2049101449bf2c8d82b022ea86b7
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
docker rmi 删除镜像
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker rmi --help
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
Options:
-f, --force Force removal of the image #强制删除
--no-prune Do not delete untagged parents #不要删除未标记的父对象
#默认最新版本按名称删除
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker rmi mysql
Untagged: mysql:latest
Untagged: mysql@sha256:52b8406e4c32b8cf0557f1b74517e14c5393aff5cf0384eff62d9e81f4985d4b
Deleted: sha256:5c62e459e087e3bd3d963092b58e50ae2af881076b43c29e38e2b5db253e0287
Deleted: sha256:b92a81bddd621ceee73e48583ed5c4f0d34392a5c60adf37c0d7acc98177e414
Deleted: sha256:265829a9fa8318ae1224f46ab7bc0a10d12ebb90d5f65d71701567f014685a9e
Deleted: sha256:2b9144b43d615572cb4a8fb486dfad0f78d1748241e49adab91f6072183644e9
Deleted: sha256:944ffc10a452573e587652116c3217cf571a32c45a031b79fed518524c21fd4f
Deleted: sha256:b9108f19e3abf550470778a9d91959ce812731d3268d7224e328b0f7d8a73d26
#指定id删除
docker rmi 09361feeb475
#指定多个id
docker rmi 09361feeb475 09361feeb475 09361feeb475
#配合docker images
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker rmi -f $(docker images -aq)
Untagged: mysql:5.7
Untagged: mysql@sha256:1a2f9cd257e75cc80e9118b303d1648366bc2049101449bf2c8d82b022ea86b7
Deleted: sha256:09361feeb4753ac9da80ead4d46e2b21247712c13c9ee3f1e5d55630c64c544f
Deleted: sha256:e454d1e47d2f346e0b2365c612cb6f12476ac4a3568ad5f62d96aa15bccf3e19
Deleted: sha256:e0457c6e331916c8ac6838ef4b22a6f62b21698facf4e143aa4b3863f08cf7d2
Deleted: sha256:ed73046ee2cd915c08ed37a545e1b89da70dc9bafeacfbd9fddff8f967373941
Deleted: sha256:419d7a76abf4ca51b81821da16a6c8ca6b59d02a0f95598a2605a1ed77c012eb
Deleted: sha256:9aecb80117a5517daf84c1743af298351a08e48fa04b8e99dcb63c817326a748
Deleted: sha256:d8773288899b1230986eba7486009df11d5dd6c628b1d4fd0443e873c6b00f70
Deleted: sha256:45a0a6bb39a4d7b37a6c598ae6af47f8a36ef63eaa9ef92d565137156aa36f54
Deleted: sha256:341f6b75346e72e9fa503aeb5362d1fe4f00449e02d3320e5c68f3052b7c2c13
Deleted: sha256:023f47f19f876ffa0225502a85b30954a44e54dc8223329fec32b336315c75c3
Deleted: sha256:058c443dffe18a5d2aad04cd5451a8540c7272ce9f8515d27e815303b1c25b59
Deleted: sha256:764055ebc9a7a290b64d17cf9ea550f1099c202d83795aa967428ebdf335c9f7
Untagged: centos:latest
Untagged: centos@sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Deleted: sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55
Deleted: sha256:2653d992f4ef2bfd27f94db643815aa567240c37732cae1405ad1c1309ee9859
容器命令
docker run 启动容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
#进入容器
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cgroupns string Cgroup namespace to use (host|private)
'host': Run the container in the Docker host's cgroup namespace
'private': Run the container in its own private cgroup namespace
'': Use the cgroup namespace as configured by the
default-cgroupns-mode option on the daemon (default)
--cidfile string Write the container ID to the file
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
#cpu权重
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
#后台运行
-d, --detach Run container in background and print container ID
--detach-keys string Override the key sequence for detaching a container
--device list Add a host device to the container
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns list Set custom DNS servers
--dns-option list Set DNS options
--dns-search list Set custom DNS search domains
--domainname string Container NIS domain name
--entrypoint string Overwrite the default ENTRYPOINT of the image
#设置环境变量
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
--group-add list Add additional groups to join
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown
(ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
#容器主机名
-h, --hostname string Container host name
--init Run an init inside the container that forwards signals and reaps processes
#以交互模式运行容器,通常与 -t 同时使用;
-i, --interactive Keep STDIN open even if not attached
--ip string IPv4 address (e.g., 172.30.100.104)
--ip6 string IPv6 address (e.g., 2001:db8::33)
--ipc string IPC mode to use
--isolation string Container isolation technology
--kernel-memory bytes Kernel memory limit
#在容器上设置元数据
-l, --label list Set meta data on a container
--label-file list Read in a line delimited file of labels
--link list Add link to another container
--link-local-ip list Container IPv4/IPv6 link-local addresses
--log-driver string Logging driver for the container
--log-opt list Log driver options
--mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33)
#内存限制
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
--mount mount Attach a filesystem mount to the container
--name string Assign a name to the container
--network network Connect a container to a network
--network-alias list Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set -1 for unlimited)
--platform string Set platform if server is multi-platform capable
--privileged Give extended privileges to this container
#暴露端口
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
--pull string Pull image before running ("always"|"missing"|"never") (default "missing")
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt list Security Options
--shm-size bytes Size of /dev/shm
--sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop a container (default "SIGTERM")
--stop-timeout int Timeout (in seconds) to stop a container
--storage-opt list Storage driver options for the container
--sysctl map Sysctl options (default map[])
--tmpfs list Mount a tmpfs directory
#为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-t, --tty Allocate a pseudo-TTY
--ulimit ulimit Ulimit options (default [])
#用户名或id
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
#数据卷挂在
-v, --volume list Bind mount a volume
--volume-driver string Optional volume driver for the container
--volumes-from list Mount volumes from the specified container(s)
#容器内工作目录
-w, --workdir string Working directory inside the container
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5c62e459e087 5 days ago 556MB
centos latest 300e315adb2f 6 months ago 209MB
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run -it -p8080:8080 --name=centoszhao56 centos /bin/bash
#说明 交互运行,映射端口8080 名称为centoszhao56 进入目录为/bin/bash
[root@c4f10db63a75 /]# ll
#镜像中有些命令没有为了减少镜像的大小
bash: ll: command not found
[root@c4f10db63a75 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@c4f10db63a75 /]# exit
exit#退出
#退出后容器停止
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c4f10db63a75 centos "/bin/bash" 2 minutes ago Exited (0) About a minute ago centoszhao56
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run -d -p8080:8080 --name=centoszhao56 centos /bin/bash
34591a8a273aa72f01a5e3b563e089c5fa666822c8721560067d638c871c4aba
#后台运行
docker ps 查看运行的容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps --help
Usage: docker ps [OPTIONS]
List containers
Options:
#所有的容器
-a, --all Show all containers (default shows just running)
#过滤
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print containers using a Go template
#显示最近几条创建的
-n, --last int Show n last created containers (includes all states) (default -1)
#显示最近创建的
-l, --latest Show the latest created container (includes all states)
--no-trunc Don't truncate output
#只显示id
-q, --quiet Only display container IDs
#显示尺寸
-s, --size Display total file sizes
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34591a8a273a centos "/bin/bash" 18 minutes ago Exited (0) 18 minutes ago centoszhao56
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -f name="centoszhao56"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -f image="centos"
Error response from daemon: Invalid filter 'image'
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -n 2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34591a8a273a centos "/bin/bash" 19 minutes ago Exited (0) 19 minutes ago centoszhao56
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -n 0
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -n 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34591a8a273a centos "/bin/bash" 19 minutes ago Exited (0) 19 minutes ago centoszhao56
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34591a8a273a centos "/bin/bash" 19 minutes ago Exited (0) 19 minutes ago centoszhao56
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -q
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -aq
34591a8a273a
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -as
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
34591a8a273a centos "/bin/bash" 22 minutes ago Exited (0) 22 minutes ago centoszhao56 0B (virtual 209MB)
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34591a8a273a centos "/bin/bash" 22 minutes ago Exited (0) 22 minutes ago centoszhao56
docker rm 删除容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker rm --help
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
#强制移除正在运行的容器
-f, --force Force the removal of a running container (uses SIGKILL)
#移除指定的连接
-l, --link Remove the specified link
#移除和容器的挂在卷
-v, --volumes Remove anonymous volumes associated with the container
#一个运行中容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
df3cf33bf4a4 centos "/bin/bash" 2 minutes ago Up 2 minutes elastic_hodgkin
#删除所有容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker ps -a -q|xargs docker rm
Error response from daemon: You cannot remove a running container df3cf33bf4a4632038199b5f5b52f2116ff62db28a714a1b9e74c3a17a874149. Stop the container before attempting removal or force remove
#删除所有容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker rm $(docker ps -aq)
Error response from daemon: You cannot remove a running container df3cf33bf4a4632038199b5f5b52f2116ff62db28a714a1b9e74c3a17a874149. Stop the container before attempting removal or force remove
#删除指定容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker rm df3cf33bf4a4
Error response from daemon: You cannot remove a running container df3cf33bf4a4632038199b5f5b52f2116ff62db28a714a1b9e74c3a17a874149. Stop the container before attempting removal or force remove
#强制删除容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker rm -f df3cf33bf4a4
df3cf33bf4a4
docker start 启动容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker start --help
Usage: docker start [OPTIONS] CONTAINER [CONTAINER...]
Start one or more stopped containers
Options:
#在前台运行容器并输出日志
-a, --attach Attach STDOUT/STDERR and forward signals
--detach-keys string Override the key sequence for detaching a container
#启动并进入交互模式
-i, --interactive Attach container's STDIN
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker start -a e0edc3f6607b
sh-4.4# 122
^C#ctrl+c退出
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker stop e0edc3f6607b
e0edc3f6607b
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker start -i e0edc3f6607b
sh-4.4# ^C #ctrl+c无法退出
sh-4.4# ^C
sh-4.4# ^C
sh-4.4# ^C
sh-4.4# exit #exit才能退出
exit
docker restart 重启容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker restart --help
Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]
Restart one or more containers
Options:
#在杀掉容器前等待几秒的停止时间
-t, --time int Seconds to wait for stop before killing the container (default 10)
docker stop 停止容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker stop --help
Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
Stop one or more running containers
Options:
-t, --time int Seconds to wait for stop before killing it (default 10)
docker kill 停止容器
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker kill --help
Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
Kill one or more running containers
Options:
-s, --signal string Signal to send to the container (default "KILL")
docker logs 查看日志
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
-n, --tail string Number of lines to show from the end of the logs (default "all")
-t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker logs -f e0edc3f6607b
sh-4.4# exit
sh-4.4# exit
sh-4.4# ^C
sh-4.4# ^C
sh-4.4# ^C
sh-4.4# ^C
sh-4.4# exit
exit
sh-4.4# exit
sh-4.4# exit
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker logs -n 3 e0edc3f6607b
exit
sh-4.4# exit
sh-4.4# exit
[root@iZ2ze9fp041k3gtah0ztnmZ /]# docker logs -t e0edc3f6607b
sh-4.4# exit
sh-4.4# exit
sh-4.4# ^C
2021-06-29T05:46:30.338694387Z sh-4.4# ^C
2021-06-29T05:46:30.828044562Z sh-4.4# ^C
2021-06-29T05:46:31.236325127Z sh-4.4# ^C
2021-06-29T05:46:33.803287777Z sh-4.4# exit
2021-06-29T05:46:33.803308993Z exit
2021-06-29T05:51:31.320164762Z sh-4.4# exit
2021-06-29T05:52:08.151149140Z sh-4.4# exit
docker top 查看容器中的进程信息
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker top e0edc3f6607b
UID PID PPID C STIME TTY TIME CMD
root 5311 5291 0 13:59 ? 00:00:00 /bin/sh
docker inspect 查看容器信息
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker inspect --help
Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]
Return low-level information on Docker objects
Options:
#格式化输出
-f, --format string Format the output using the given Go template
-s, --size Display total file sizes if the type is container
--type string Return JSON for specified type
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker inspect e0edc3f6607b
[
{
#容器id
"Id": "e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6",
#容器创建时间
"Created": "2021-06-29T05:05:55.67220732Z",
#进入路径
"Path": "/bin/sh",
#参数
"Args": [],
#状态
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 5311,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-06-29T05:59:53.178150805Z",
"FinishedAt": "2021-06-29T05:52:08.152440764Z"
},
#镜像id
"Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
#解析路径
"ResolvConfPath": "/var/lib/docker/containers/e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6/resolv.conf",
#主机名路径
"HostnamePath": "/var/lib/docker/containers/e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6/hostname",
#主机路径
"HostsPath": "/var/lib/docker/containers/e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6/hosts",
#日志路径
"LogPath": "/var/lib/docker/containers/e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6/e0edc3f6607b2dd17401fdad3dbfb3826def1e4254c82003e428dcb9f90cdff6-json.log",
#容器名称
"Name": "/zhao56centos",
"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/fb645b5d03e4c4c83d7b2a6b28fefe811a3c566407a3ebd33a302d9d3b9da19b-init/diff:/var/lib/docker/overlay2/9667d7dfaa26c94f6ddade4b6a36a9b5e7a8f19068e7648b04c5afb6b4a2b4d1/diff",
"MergedDir": "/var/lib/docker/overlay2/fb645b5d03e4c4c83d7b2a6b28fefe811a3c566407a3ebd33a302d9d3b9da19b/merged",
"UpperDir": "/var/lib/docker/overlay2/fb645b5d03e4c4c83d7b2a6b28fefe811a3c566407a3ebd33a302d9d3b9da19b/diff",
"WorkDir": "/var/lib/docker/overlay2/fb645b5d03e4c4c83d7b2a6b28fefe811a3c566407a3ebd33a302d9d3b9da19b/work"
},
"Name": "overlay2"
},
"Mounts": [],
#配置信息
"Config": {
"Hostname": "e0edc3f6607b",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": true,
"OpenStdin": true,
"StdinOnce": false,
#环境变量
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh"
],
"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": "eb12709fc4dcf4455c655edbd41592cba408aa8aa18cb5ff9483739ac2733549",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/eb12709fc4dc",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "1f02a86015bf988862f00ebcee52842f69dbc4ba37783232a749fb879995b9c0",
"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": "228e778842de1d2d5fd1dceecd54e1d785b0fedd03699af08b7466aba2ad9c31",
"EndpointID": "1f02a86015bf988862f00ebcee52842f69dbc4ba37783232a749fb879995b9c0",
"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 进入容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker exec --help
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
#分离模式:在后台运行命令,
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
#设置环境变量
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
#交互模式,通常与t配合
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
#容器内的工作目录
-w, --workdir string Working directory inside the container
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker exec -it zhao56centos /bin/bash echo "hello"
[root@e0edc3f6607b /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
docker attach 进入容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker attach --help
Usage: docker attach [OPTIONS] CONTAINER
Attach local standard input, output, and error streams to a running container
Options:
--detach-keys string Override the key sequence for detaching a container
--no-stdin Do not attach STDIN
--sig-proxy Proxy all received signals to the process (default true)
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker attach e0edc3f6607b
sh-4.4# exit
exit
docker attach 和exec的区别
docker exec 进入容器后开启一个新的终端,可以在里面操作
docker attach 进入容器正在执行的终端,不会启动新的进程
docker cp 将容器拷贝文件到主机上
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker cp --help
Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Copy files/folders between a container and the local filesystem
Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.
Options:
#存档模式
-a, --archive Archive mode (copy all uid/gid information)
-L, --follow-link Always follow symbol link in SRC_PATH
开启两个客户端,一个进入容器
客户端
两个home下面都没有东西
在容器中创建文件,由于容器中没有vim所以先安装vim,然后创建test.java文件
yum -y install vim*
[root@e0edc3f6607b home]# vim test.java
[root@e0edc3f6607b home]# cat test.java
123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321
[root@iZ2ze9fp041k3gtah0ztnmZ home]# ll
total 0
#拷贝文件
[root@iZ2ze9fp041k3gtah0ztnmZ home]# docker cp e0edc3f6607b:/home/test.java /home
[root@iZ2ze9fp041k3gtah0ztnmZ home]# ll
total 4
-rw-r--r-- 1 root root 739 Jun 29 14:42 test.java
[root@iZ2ze9fp041k3gtah0ztnmZ home]# cat test.java
123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321123321
#内容一致,之后可以用挂在的形式实现自动同步文件
docker stats 显示容器资源使用统计信息的实时流
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker stats --help
Usage: docker stats [OPTIONS] [CONTAINER...]
Display a live stream of container(s) resource usage statistics
Options:
-a, --all Show all containers (default shows just running)
--format string Pretty-print images using a Go template
--no-stream Disable streaming stats and only pull the first result
--no-trunc Do not truncate output
如上图可以看到资源使用的一些统计信息
小结
再次附上网上找到的总结的图
练习
部署ngnix
#下载镜像
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b4d181a07f80: Pull complete
edb81c9bc1f5: Pull complete
b21fed559b9f: Pull complete
03e6a2452751: Pull complete
b82f7f888feb: Pull complete
5430e98eba64: Pull complete
Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
#启动容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run -d --name nginx01 -p 3344:80 nginx
d220177f71aff527de51255d4a997c585523645282cb85591256c254b285ef1f
#容器正常运行
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d220177f71af nginx "/docker-entrypoint.…" 41 seconds ago Up 40 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
#测试访问
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#进入容器
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker exec -it nginx01 /bin/bash
root@d220177f71af:/# cd /etc/nginx
#查看文件
root@d220177f71af:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
每次需要修改nginx配置文件都要进入容器内部修改,非常麻烦
部署tomcat
#下载tomcat
docker pull tomcat:9.0
#运行
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
9da304ebcdd8d0d0a255a7bba5c005392c33416b14998ec3877b551c5f3c2c6f
#进入容器 查看文件
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker exec -it tomcat01 /bin/bash
root@9da304ebcdd8:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
root@9da304ebcdd8:/usr/local/tomcat# ls -al
total 176
drwxr-xr-x 1 root root 4096 Jun 26 05:03 .
drwxr-xr-x 1 root root 4096 Jun 29 08:11 ..
-rw-r--r-- 1 root root 18949 Jun 10 09:22 BUILDING.txt
-rw-r--r-- 1 root root 6210 Jun 10 09:22 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Jun 10 09:22 LICENSE
-rw-r--r-- 1 root root 2333 Jun 10 09:22 NOTICE
-rw-r--r-- 1 root root 3372 Jun 10 09:22 README.md
-rw-r--r-- 1 root root 6898 Jun 10 09:22 RELEASE-NOTES
-rw-r--r-- 1 root root 16507 Jun 10 09:22 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jun 26 05:03 bin
drwxr-xr-x 1 root root 4096 Jun 29 08:11 conf
drwxr-xr-x 2 root root 4096 Jun 26 05:03 lib
drwxrwxrwx 1 root root 4096 Jun 29 08:11 logs
drwxr-xr-x 2 root root 4096 Jun 26 05:03 native-jni-lib
drwxrwxrwx 2 root root 4096 Jun 26 05:03 temp
drwxr-xr-x 2 root root 4096 Jun 26 05:03 webapps
drwxr-xr-x 7 root root 4096 Jun 10 09:22 webapps.dist
drwxrwxrwx 2 root root 4096 Jun 10 09:22 work
#命令少、webapps下方没有东西
root@9da304ebcdd8:/usr/local/tomcat# ll
bash: ll: command not found
root@9da304ebcdd8:/usr/local/tomcat# cd webapps
root@9da304ebcdd8:/usr/local/tomcat/webapps# ls
root@9da304ebcdd8:/usr/local/tomcat/webapps# cd ..
root@9da304ebcdd8:/usr/local/tomcat# cd webapps.dist/
root@9da304ebcdd8:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
#将webapps.dust下的文件拷贝到webapps下
root@9da304ebcdd8:/usr/local/tomcat/webapps.dist# cd ..
root@9da304ebcdd8:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@9da304ebcdd8:/usr/local/tomcat# cd webapps
root@9da304ebcdd8:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
#测试
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# curl localhost:3355
#发现可以访问
部署es
#下载并启动es
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
Unable to find image 'elasticsearch:7.6.2' locally
7.6.2: Pulling from library/elasticsearch
ab5ef0e58194: Pull complete
c4d1ca5c8a25: Pull complete
941a3cc8e7b8: Pull complete
43ec483d9618: Pull complete
c486fd200684: Pull complete
1b960df074b2: Pull complete
1719d48d6823: Pull complete
Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa
Status: Downloaded newer image for elasticsearch:7.6.2
20241004d84156a41bf3baff06091b76bbe027c89cef09e5978edb94390867b3
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20241004d841 elasticsearch:7.6.2 "/usr/local/bin/dock…" 5 seconds ago Up 4 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
#系统占用内存特别大 看图一
#限制内存启动方法 -e修改环境变量 看图二
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# 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
#测试
[root@iZ2ze9fp041k3gtah0ztnmZ ~]# curl localhost:9200
{
"name" : "946b0ac6be9d",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "gY2n1zMfS5ah52Nw1RDyqQ",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
#没问题!!
图二
本文来自博客园,作者:zhao56,转载请注明原文链接:https://www.cnblogs.com/zhao56/p/14950948.html