docker 端口映射

docker 删除所有容器 必须先停再删,再启动
[root@localhost ~]#
[root@localhost ~]# docker rm $(docker ps -qa)
1f2abcd6ae16
Error response from daemon: cannot remove container "/c1": container is running: stop the container before removing or force remove
Error response from daemon: cannot remove container "/c7": container is running: stop the container before removing or force remove
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker stop c1
c1
[root@localhost ~]# docker stop c7
c7
[root@localhost ~]# docker rm $(docker ps -qa)
a2e58a56047d
e40e729d2da2
[root@localhost ~]#
[root@localhost ~]#

[root@localhost ~]#
[root@localhost ~]# docker run --name nginx -d nginx:latest
68b6d46d483fd0094c0e3c6fae62ab31a35576b042079fadc666bb8b6f95d913
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68b6d46d483f nginx:latest "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 80/tcp nginx
[root@localhost ~]#
[root@localhost ~]#
启动nginx容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68b6d46d483f nginx:latest "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 80/tcp nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker stop nginx
nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker rm nginx
nginx
[root@localhost ~]#
删除nginx做端口印射
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68b6d46d483f nginx:latest "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 80/tcp nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker stop nginx
nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker rm nginx
nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker run --name nginx -p 80:80 -d nginx:latest
a4fa9d11f864bfe15fc6e4c06aa441ed2390044d2b4a3cc958aaf70881aa9a40
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4fa9d11f864 nginx:latest "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vim 1.sh
[root@localhost ~]#
[root@localhost ~]# sh 1.sh
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
=== firewalld已关闭并禁用 ===
=== SELinux已临时关闭,且配置为永久禁用 ===
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
=== NetworkManager已关闭并禁用 ===
所有安全组件已按要求关闭完成!
[root@localhost ~]#
[root@localhost ~]#


真实机80端口映射
[root@localhost ~]#
[root@localhost ~]# docker logs -f nginx
/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: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/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
2025/10/25 08:59:58 [notice] 1#1: using the "epoll" event method
2025/10/25 08:59:58 [notice] 1#1: nginx/1.29.2
2025/10/25 08:59:58 [notice] 1#1: built by gcc 14.2.0 (Debian 14.2.0-19)
2025/10/25 08:59:58 [notice] 1#1: OS: Linux 3.10.0-957.el7.x86_64
2025/10/25 08:59:58 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 65536:65536
2025/10/25 08:59:58 [notice] 1#1: start worker processes
2025/10/25 08:59:58 [notice] 1#1: start worker process 28
2025/10/25 08:59:58 [notice] 1#1: start worker process 29
172.17.0.1 - - [25/Oct/2025:09:02:03 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0" "-"
172.17.0.1 - - [25/Oct/2025:09:02:03 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://10.1.1.128/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0" "-"
2025/10/25 09:02:03 [error] 28#28: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "10.1.1.128", referrer: "http://10.1.1.128/"
2025/10/25 09:08:20 [error] 28#28: *3 open() "/usr/share/nginx/html/zabbix" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /zabbix HTTP/1.1", host: "10.1.1.128"
172.17.0.1 - - [25/Oct/2025:09:08:20 +0000] "GET /zabbix HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0" "-"
^C
[root@localhost ~]#
看日志:
docker logs -f nginx
浙公网安备 33010602011771号