##需要修改docker配置文件,配置支持IPV6,下面的配置仅供参考
{
"experimental": true,
"fixed-cidr-v6": "2607:f0d0:1002:51::/66", ## 必填,指定IPV6网段
"ip6tables": false, ## false 或者不写
"ipv6": true, ## 必填
"registry-mirrors": [ ## 推荐配置为国内地址,这里使用的是阿里云地址
"https://z4j0vmao.mirror.aliyuncs.com"
]
}
docker run -d --name centos7-port --privileged=true -p 80:80 -p 8080:8080 -p 8088:8088 -v D:/docker/centos/home:/home centos:centos7.9.2009 /usr/sbin/init
命令 | 含义 |
---|---|
–name centos7-port | 容器名字叫 centos7-port |
–privileged=true | 获取特权 |
-p 80:80 -p 8080:8080 -p 8088:8088 | 映射80 8080 8088 三个端口 |
-v D:/docker/centos/home:/home | 将本机 D:/docker/centos/home 映射到容器的 /home |
centos:centos7.9.2009 | 指定使用的镜像,没有的先下载 |
/usr/sbin/init | 初始化容器 |
yum update -y
sh-4.2# yum install net-tools
sh-4.2# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
## 下面就是IPV6地址,但是注意,这是容器的地址,并是不主机的地址,要访问的也不是这个地址
inet6 2607:f0d0:1002:51:0:242:ac11:2 prefixlen 66 scopeid 0x0<global>
inet6 fe80::42:acff:fe11:2 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 111287 bytes 162126536 (154.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 29610 bytes 1984231 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
sh-4.2#
sh-4.2# ping6 2607:f0d0:1002:51:0:242:ac11:2
PING 2607:f0d0:1002:51:0:242:ac11:2(2607:f0d0:1002:51:0:242:ac11:2) 56 data bytes
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=1 ttl=64 time=0.023 ms
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=3 ttl=64 time=0.023 ms
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=4 ttl=64 time=0.071 ms
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=5 ttl=64 time=0.092 ms
64 bytes from 2607:f0d0:1002:51:0:242:ac11:2: icmp_seq=6 ttl=64 time=0.083 ms
^C
--- 2607:f0d0:1002:51:0:242:ac11:2 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5210ms
rtt min/avg/max/mdev = 0.023/0.052/0.092/0.031 ms
我测试不需要这样,根据具体以情况选择是否执行
[root@localhost ~]# ip6tables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost ~]# Service ip6tables save
yum install wget -y
sh-4.2# cd /home/
sh-4.2# mkdir nginx
sh-4.2# cd ./nginx
wget https://nginx.org/download/nginx-1.4.6.tar.gz
yum install -y pcre pcre-devel gcc gcc-c++ zlib zlib-devel openssl openssl-devel iptables-ipv6
tar -xzvf nginx-1.4.6.tar.gz
sh-4.2# mkdir nginxInstall
sh-4.2# cd ./nginxInstall/
sh-4.2# pwd
/home/nginx/nginxInstall
sh-4.2#
sh-4.2# cd ./nginx-1.4.6
sh-4.2# pwd
/home/nginx/nginx-1.4.6
sh-4.2#./configure --prefix=/home/nginx/nginxInstall --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
make && make install
sh-4.2# pwd
/home/nginx/nginx-1.4.6
sh-4.2# ls
CHANGES CHANGES.ru LICENSE Makefile README auto conf configure contrib html man objs src
## 安装编辑器
sh-4.2# yum install vim -y
sh-4.2# vim /etc/profile
## 演示环境是新创建的容器,没有多余的环境变量,增加如下两行
export NGINX_HOME=/home/nginx/nginxInstall
export PATH=$NGINX_HOME/sbin:$PATH
## 刷新环境变量
sh-4.2# source /etc/profile
sh-4.2# pwd
/home/nginx/nginx-1.4.6
sh-4.2# nginx
sh-4.2# ps -ef|grep nginx
root 2723 1 0 06:47 ? 00:00:00 nginx: master process nginx
nobody 2724 2723 0 06:47 ? 00:00:00 nginx: worker process
root 2726 63 0 06:47 pts/0 00:00:00 grep --color=auto nginx
sh-4.2#
由于使用的是虚拟机,并将端口与主机共享,所有使用主机地址测试
使用主机浏览器访问 http://127.0.0.1/
出现Nginx 环境页面说明安装正常
sh-4.2# cd /home/nginx/nginxInstall/conf/
sh-4.2# cp nginx.conf nginx.conf.backup
sh-4.2# vim nginx.conf
## 在 nginx.conf 中增加 listen [::]:80; 如下:
server {
listen 80;
listen [::]:80;
## 测试Nginx 是否正常
sh-4.2# nginx -t
nginx: the configuration file /home/nginx/nginxInstall/conf/nginx.conf syntax is ok
nginx: configuration file /home/nginx/nginxInstall/conf/nginx.conf test is successful
## 重新加载Nginx
sh-4.2# nginx -s reload
sh-4.2# curl -6 -g 'http://[2607:f0d0:1002:51:0:242:ac11:2]:80'
<!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>
sh-4.2# wget -6 'http://[2607:f0d0:1002:51:0:242:ac11:2]:80'
--2023-06-12 02:15:23-- http://[2607:f0d0:1002:51:0:242:ac11:2]/
Connecting to [2607:f0d0:1002:51:0:242:ac11:2]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 612 [text/html]
Saving to: 'index.html'
100%[=====================================================================================================>] 612 --.-K/s in 0s
2023-06-12 02:15:23 (146 MB/s) - 'index.html' saved [612/612]
sh-4.2#
sh-4.2# yum install telnet-server
sh-4.2# yum install telnet.*
sh-4.2# telnet -6 2607:f0d0:1002:51:0:242:ac11:2 80
Trying 2607:f0d0:1002:51:0:242:ac11:2...
Connected to 2607:f0d0:1002:51:0:242:ac11:2.
Escape character is '^]'.
^CConnection closed by foreign host.
sh-4.2#