前提是你肯定在你电脑上安装了docker
记得去配置一下阿里云加速的配置,不然你拉去镜像非常慢,话不多说,直接开始上手,建议把下文所有涉及到的命令自己敲一遍,下一篇还会降到docker高级用法,本篇只是基础入门!冲冲冲!
帮助命令
docker version
docker info
docker 命令 --help
镜像命令
docker images
可选项
-a ,-all 列出所有镜像
-q ,-quiet 只显示出镜像的id
docker search 搜索镜像
可选项
--filter=STARTS=3000
docker pull 镜像名:tag
docker rmi -f 镜像id [镜像id]
docker rmi -f $(docker images -aq)
容器命令
新建容器并启动
docker run [可选参数] 镜像
#参数说明
--name="Name" 给容器起一个名字
-d 以后台方式运行
-it 目录 使用交互方式运行,进入容器查看内容
-p 指定容器端口 80:80
-p 主机端口:容器端口
-p 容器端口
-p ip:主机端口:容器端口
容器端口
-P 随机指定端口
列出所有的运行的容器
docker ps
-a
-n=? 显示最近的具体几个
-q 只显示容器的编号
退出容器
exit 退出并停止
ctrl+p+q 容器不停止退出
删除容器
docker rm 容器id 删除指定的容器,不能删除运行的容器
docker rm -f $(docker ps -aq) 删除所有的容器
docker ps -a -q|xargs docker rm
启动停止容器
docker start 容器id
docker restart 容器id
docker stop 容器id
docker kill 容器id
常用的其他命令
后台启动应用
docker run -d 容器名
查看日志
-tf 显示日志
--tail number 要显示日志条数
docker logs -tf --tail 10 容器id 显示指定函数的日志
查看进程信息
docker top 容器id
查看镜像的元数据
docker inspect 镜像id
[
{
"Id": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
"RepoTags": [
"centos:latest"
],
"RepoDigests": [
"centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177"
],
"Parent": "",
"Comment": "",
"Created": "2021-09-15T18:20:05.184694267Z",
"Container": "9bf8a9e2ddff4c0d76a587c40239679f29c863a967f23abf7a5babb6c2121bf1",
"ContainerConfig": {
"Hostname": "9bf8a9e2ddff",
"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",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"Image": "sha256:f5b050f177fd426be8fe998a8ecf3fb1858d7e26dff4080b29a327d1bd5ba422",
"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"
}
},
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"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/bash"
],
"Image": "sha256:f5b050f177fd426be8fe998a8ecf3fb1858d7e26dff4080b29a327d1bd5ba422",
"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"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 231268856,
"VirtualSize": 231268856,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/b7962b6f0da839a54227e65e3dbb2773198fdeed81d90e7793ae3e6ecaa703af/merged",
"UpperDir": "/var/lib/docker/overlay2/b7962b6f0da839a54227e65e3dbb2773198fdeed81d90e7793ae3e6ecaa703af/diff",
"WorkDir": "/var/lib/docker/overlay2/b7962b6f0da839a54227e65e3dbb2773198fdeed81d90e7793ae3e6ecaa703af/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
进入正在运行的容器
docker exec -it 容器id bashShell
C:\Users\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
379bfaccaf2e centos "/bin/bash" 25 minutes ago Up 25 minutes intelligent_babbage
C:\Users\>docker exec -it 379bfaccaf2e /bin/bash
[root@379bfaccaf2e /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 00:52 pts/0 00:00:00 /bin/bash
root 16 0 0 01:18 pts/1 00:00:00 /bin/bash
root 30 16 0 01:18 pts/1 00:00:00 ps -ef
docker attach 容器id
从容器内拷贝东西到主机内
docker cp 容器id:容器内路径 目的主机路径
练习
部署nginx
C:\Users\> docker run -d --name nginx01 -p 3344:80 nginx
654283b0a5626ad5b5c90b7a675b844e0925b16721b5a749ba1d2f9e04d6ee31
C:\Users\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
654283b0a562 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:3344->80/tcp nginx01
C:\Users\>curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
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>
部署tomcat
docker run -it --rm tomcat
部署es+kibana
docker status 查看cpu的状态
commit镜像
docker commit 提交容器成为一个新的副本
docker commit -m='提交的信息描述' -a='作者' 容器id 目标镜像名:[TAG]
C:\Users\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3867a5b1e084 tomcat "catalina.sh run" 4 minutes ago Up 4 minutes 0.0.0.0:8083->8080/tcp tomcat01
C:\Users\>docker commit -a="aihua" -m="add webapps app" 3867a5b1e084 tomcat02:1.0
sha256:3e1c13340f0aea8f0a2b50427570151028a40aef58e7b56a3c5ebd5104ddaeda
本文转载自: https://blog.csdn.net/2301_76875881/article/details/131338829
版权归原作者 ApachHua 所有, 如有侵权,请联系我们删除。
版权归原作者 ApachHua 所有, 如有侵权,请联系我们删除。