1. 搜索http镜像
[root@localhost ~]# docker search http
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
httpd The Apache HTTP Server Project 3909 [OK]
haproxy HAProxy - The Reliable, High Performance TCP?? 1704 [OK]
sentry DEPRECATED; https://develop.sentry.dev/self-?? 614 [OK]
couchdb CouchDB is a database that uses JSON for doc?? 460 [OK]
caddy Caddy 2 is a powerful, enterprise-ready, ope?? 358 [OK]
adoptopenjdk DEPRECATED; use https://hub.docker.com/_/ecl?? 338 [OK]
docker/compose Define and run multi-container applications ?? 152
percona/percona-xtradb-cluster Percona XtraDB Cluster docker image | https:?? 150
varnish Varnish is an HTTP accelerator designed for ?? 117 [OK]
docker-dev DEPRECATED; use https://github.com/moby/moby?? 97 [OK]
fsharp DEPRECATED; use https://hub.docker.com/_/mic?? 79 [OK]
portainer/templates App Templates for Portainer http://portainer?? 24
ubuntu/apache2 Apache, a secure & extensible open-source HT?? 23
google/dart-hello Image for a simple Dart HTTP server 16
ibmcom/ibmnode This image has been deprecated, please use t?? 8
sysdig/falco Falco has been moved to https://hub.docker.c?? 4 [OK]
purestorage/docker-plugin See certified image at https://store.docker.?? 4
rancher/k3d Little helper to run Rancher Lab's k3s in Do?? 3
circleci/rabbitmq-delayed https://github.com/circleci/rabbitmq-delayed?? 1
atlassian/pipelines-auth-proxy A sidecar that acts as a git http(s) proxy t?? 1
neo4j/neo4j-dcos-proxy A HTTP proxy to expose Neo4j Browser HTTP co?? 0
docker/trusttest Image that supports these docs: https://doc?? 0
ibmcom/httprequest-ppc64le Docker image for httprequest-ppc64leDocker i?? 0
bitnami/http-trigger-controller 0
sysdig/kubewatcher https://github.com/draios/sysdig-kube-watcher 0
2. 拉取一个http镜像
[root@localhost ~]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
a2abf6c4d29d: Already exists
dcc4698797c8: Pull complete
41c22baa66ec: Pull complete
67283bbdd4a0: Pull complete
d982c879c57e: Pull complete
Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
3. 查看拉取的镜像,可以看到刚刚拉取的http镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 months ago 141MB
httpd latest dabbfbe0c57b 2 months ago 144MB
4. 删除镜像,如果加上 -f参数就是强制删除
[root@localhost ~]# docker rmi dabbfbe0c57b
Untagged: httpd:latest
Untagged: httpd@sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Deleted: sha256:dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
Deleted: sha256:0e16a5a61bcb4e6b2bb2d746c2d6789d6c0b66198208b831f74b52198d744189
Deleted: sha256:f79670638074ff7fd293e753c11ea2ca0a2d92ab516d2f6b0bac3f4c6fed5d86
Deleted: sha256:189d55cdd18e4501032bb700a511c2d69c82fd75f1b619b5218ea6870e71e4aa
Deleted: sha256:cb038ed3e490a8c0f195cf135ac0d27dd8d3872598b1cb858c2666f2dae95a61
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 months ago 141MB
5. 创建一个容器
参数:
–name 指定容器的名字
-d 后台启动这个容器
-P 自动端口映射
-p 8888:80 手动将容器里面的80端口映射到宿主机的8080端口
-it 指定/bin/bash交互式创建一个容器(创建时直接进入容器)
-v 挂载一个持久卷到容器指定目录(很有用)
[root@localhost ~]# docker run --name nginx01 -d -P nginx
2cd1473c04204e962b5af245f911946d481a7eb42be1da5bf9379cfd59757486
[root@localhost ~]# docker run --name nginx02 -d -p 8888:80 nginx
e15d309f5a90ab744395d2ae3aba961a3e3af769e1bf0b60aa5d00edc1c7ac45
[root@localhost ~]# docker run -it nginx /bin/bash
root@5d2f87b58964:/#
6. 查看创建的容器;停止容器;重启容器
参数:
docker ps -a 查看所有容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e15d309f5a90 nginx "/docker-entrypoint.?? 5 minutes ago Up 5 minutes 0.0.0.0:8888->80/tcp, :::8888->80/tcp nginx02
2cd1473c0420 nginx "/docker-entrypoint.?? 9 minutes ago Up 9 minutes 0.0.0.0:49154->80/tcp, :::49154->80/tcp nginx01
da58862a0561 nginx "/docker-entrypoint.?? 40 hours ago Up 40 hours 0.0.0.0:49153->80/tcp, :::49153->80/tcp happy_sutherland
88d7e4f2b3bc nginx "/docker-entrypoint.?? 40 hours ago Up 40 hours 80/tcp, 0.0.0.0:8080->88/tcp, :::8080->88/tcp quirky_jones
[root@localhost ~]# docker stop 9da5bc27c49d
9da5bc27c49d
[root@localhost ~]# docker restart 9da5bc27c49d
9da5bc27c49d
7. 删除容器
参数:-f 强制删除
[root@localhost ~]# docker rm 5d2f87b58964
5d2f87b58964
一次性强制删除所有容器(两种方式)
[root@localhost ~]# docker rm -f $(docker ps -aq)
788d6737e0ce
e15d309f5a90
2cd1473c0420
da58862a0561
88d7e4f2b3bc
[root@localhost ~]# docker ps -aq |xargs docker rm -f
ae56422484d1
8. 进入容器(两种方式)
[root@localhost ~]# docker exec -it 9da5bc27c49d /bin/bash //进入容器后开启一个新的终端
root@9da5bc27c49d:/#
[root@localhost ~]# docker attach 9da5bc27c49d //进入容器正在执行的终端
退出容器
root@9da5bc27c49d:/# exit
exit
Ctrl+p+q 容器运行状态退出
9. 查看日志
[root@localhost ~]# docker logs 9da5bc27c49d
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/03/04 04:10:16 [notice] 1#1: using the "epoll" event method
2022/03/04 04:10:16 [notice] 1#1: nginx/1.21.5
2022/03/04 04:10:16 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/03/04 04:10:16 [notice] 1#1: OS: Linux 3.10.0-1127.el7.x86_64
2022/03/04 04:10:16 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/03/04 04:10:16 [notice] 1#1: start worker processes
2022/03/04 04:10:16 [notice] 1#1: start worker process 31
2022/03/04 04:10:16 [notice] 1#1: start worker process 32
2022/03/04 04:10:16 [notice] 1#1: start worker process 33
2022/03/04 04:10:16 [notice] 1#1: start worker process 34
10. 查看元数据
[root@localhost ~]# docker inspect 9da5bc27c49d
11. 查看进程
[root@localhost ~]# docker top 9da5bc27c49d
UID PID PPID C STIME TTY TIME CMD
root 77206 77186 0 23:19 ? 00:00:00 nginx: master process nginx -g daemon off;
101 77250 77206 0 23:19 ? 00:00:00 nginx: worker process
101 77251 77206 0 23:19 ? 00:00:00 nginx: worker process
101 77252 77206 0 23:19 ? 00:00:00 nginx: worker process
101 77253 77206 0 23:19 ? 00:00:00 nginx: worker process
12.容器里面拷贝文件到宿主机
[root@localhost ~]# docker cp 9da5bc27c49d:/home/test.txt /root 注://docker cp 容器id:文件地址 宿主机地址
13. docker信息查看docker info 和 docker version
[root@localhost ~]# docker info
[root@localhost ~]# docker version