一、检查本地系统版本 代码语言: shell
复制 [root@node ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
二、检查docker状态 代码语言: shell
复制 [root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-10-31 03:28:51 CST; 2 days ago
Docs: https://docs.docker.com
Main PID: 11884 (dockerd)
Tasks: 120
Memory: 2.7G
CGroup: /system.slice/docker.service
├─ 2014 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8580 -container-ip 172.29.0.2 -container-port 8080
├─ 2019 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8580 -container-ip 172.29.0.2 -container-port 8080
├─ 2674 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8015 -container-ip 172.28.0.2 -container-port 8080
├─ 2681 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8015 -container-ip 172.28.0.2 -container-port 8080
├─ 6972 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8380 -container-ip 172.30.0.2 -container-port 8080
├─ 6977 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8380 -container-ip 172.30.0.2 -container-port 8080
├─ 11884 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─ 34936 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.27.0.3 -container-port 80
├─ 34950 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8080 -container-ip 172.27.0.3 -container-port 80
├─ 69485 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8012 -container-ip 172.17.0.4 -container-port 8012
├─ 69490 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8012 -container-ip 172.17.0.4 -container-port 8012
├─108373 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 7090 -container-ip 172.17.0.5 -container-port 8080
├─108378 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 7090 -container-ip 172.17.0.5 -container-port 8080
├─114721 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9000 -container-ip 172.17.0.2 -container-port 9000
├─114726 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9000 -container-ip 172.17.0.2 -container-port 9000
├─125344 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5000 -container-ip 172.17.0.3 -container-port 5000
└─125350 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5000 -container-ip 172.17.0.3 -container-port 5000
Nov 02 15:16:34 node dockerd[11884]: time="2022-11-02T15:16:34.836861791 08:00" level=info msg="Download failed, retrying (4/5): Get "https://prod...
Nov 02 15:22:05 node dockerd[11884]: time="2022-11-02T15:22:05.407264707 08:00" level=error msg="Not continuing with pull after error: con...canceled"
Nov 02 15:22:05 node dockerd[11884]: time="2022-11-02T15:22:05.418587813 08:00" level=info msg="Layer sha256:4fc242d58285699eca05db3cc7c71...eaned up"
Nov 02 15:41:11 node dockerd[11884]: time="2022-11-02T15:41:11.521523907 08:00" level=info msg="Attempting next endpoint for pull after er...ogin yet"
Nov 02 15:41:11 node dockerd[11884]: time="2022-11-02T15:41:11.522439588 08:00" level=error msg="Handler for POST /v1.41/images/create ret...ogin yet"
Nov 02 19:31:41 node dockerd[11884]: time="2022-11-02T19:31:41.114772038 08:00" level=info msg="ignoring event" container=b5ee084a06da9d7a...skDelete"
Nov 02 19:37:20 node dockerd[11884]: time="2022-11-02T19:37:20.995774757 08:00" level=info msg="ignoring event" container=76f027d603614874...skDelete"
Nov 02 19:38:29 node dockerd[11884]: time="2022-11-02T19:38:29.513728257 08:00" level=info msg="ignoring event" container=464a24809eb3af8c...skDelete"
Nov 02 19:45:05 node dockerd[11884]: time="2022-11-02T19:45:05.808404003 08:00" level=info msg="ignoring event" container=66440ac8e1559536...skDelete"
Nov 02 19:50:27 node dockerd[11884]: time="2022-11-02T19:50:27.152222073 08:00" level=info msg="ignoring event" container=d9bcdb2036c3405d...skDelete"
Hint: Some lines were ellipsized, use -l to show in full.
三、搜索nginx镜像 代码语言: shell
复制 [root@node ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 17614 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 179
bitnami/nginx Bitnami nginx Docker Image 141 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 64
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 22 [OK]
rancher/nginx-ingress-controller 11
webdevops/nginx Nginx container 10 [OK]
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
bitnami/nginx-ldap-auth-daemon 3
bitnami/nginx-exporter 3
vmware/nginx 2
rancher/nginx-ingress-controller-defaultbackend 2
rapidfort/nginx RapidFort optimized, hardened image for NGINX 2
kasmweb/nginx An Nginx image based off nginx:alpine and in… 2
rancher/nginx 2
bitnami/nginx-intel 1
wallarm/nginx-ingress-controller Kubernetes Ingress Controller with Wallarm e… 1
vmware/nginx-photon 1
rancher/nginx-conf 0
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 0
ibmcom/nginx-ingress-controller-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 0
rancher/nginx-ssl 0
continuumio/nginx-ingress-ws 0
rancher/nginx-ingress-controller-amd64 0
ibmcom/nginx-ppc64le Docker image for nginx-ppc64le 0
四、创建nginx容器 1.创建数据目录 代码语言: shell
复制 [root@node ~]# mkdir /data/nginx
[root@node ~]# cd /data/nginx/
[root@node nginx]# ls
[root@node nginx]#
2.运行nginx容器 代码语言: shell
复制 [root@node nginx]# docker run -d --name my_web01 --restart always -p 8744:80 -v /data/nginx/:/usr/share/nginx/html/ nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
a2abf6c4d29d: Already exists
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
349f6f002567d13ec9a4a871b730d85173c7c9a8038067ae4d9369d091e96ba4
3.查看nginx容器状态 代码语言: shell
复制 [root@node nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
349f6f002567 nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:8744->80/tcp, :::8744->80/tcp my_web01
4.查看容器日志 代码语言: shell
复制 [root@node nginx]# docker logs my_web01
/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/11/02 16:33:36 [notice] 1#1: using the "epoll" event method
2022/11/02 16:33:36 [notice] 1#1: nginx/1.21.5
2022/11/02 16:33:36 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/11/02 16:33:36 [notice] 1#1: OS: Linux 3.10.0-957.el7.x86_64
2022/11/02 16:33:36 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 65536:65536
2022/11/02 16:33:36 [notice] 1#1: start worker processes
2022/11/02 16:33:36 [notice] 1#1: start worker process 31
2022/11/02 16:33:36 [notice] 1#1: start worker process 32
五、访问nginx 1.编辑index.html 代码语言: shell
复制 [root@node nginx]# echo "nginx aa-bb" > index.html
[root@node nginx]# pwd
/data/nginx
2.访问nginx 在这里插入图片描述