多容器共用一个网卡

本文档介绍了如何基于CentOS镜像创建多个容器,并让它们共享同一个网卡。通过拉取CentOS镜像,创建包含nginx、mysql和php的容器,所有容器都使用nginx04容器的网络接口。接着,通过容器创建新的镜像,并确保新创建的容器同样能共用同一张网卡。最后,进行了功能测试以验证网络连接的正确性。
摘要由CSDN通过智能技术生成

基于容器制作镜像

拉取一个centos镜像

[root@localhost ~]# docker pull centos
Using default tag: latest

latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   2 months ago   231MB


基于centos镜像生成一个容器

[root@localhost ~]# docker run --name nginx04 -it centos /bin/bash
[root@d46e5d7f7e13 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@d46e5d7f7e13 /]# cd /root
[root@d46e5d7f7e13 ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget

[root@d46e5d7f7e13 ~]# useradd -r -M -s /sbin/nologin nginx
[root@d46e5d7f7e13 ~]# mkdir -p /var/log/nginx
[root@d46e5d7f7e13 ~]# chown -R nginx.nginx /var/log/nginx

[root@d46e5d7f7e13 ~]# wget http://nginx.org/download/nginx-1.21.3.tar.gz
[root@d46e5d7f7e13 ~]# tar xf nginx-1.21.3.tar.gz
 
[root@d46e5d7f7e13 ~]# cd nginx-1.21.3
[root@d46e5d7f7e13 nginx-1.21.3]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@d46e5d7f7e13 nginx-1.21.3]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install


[root@d46e5d7f7e13 ~]# echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf

//修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
......
#在45行中添加index.php
45             index  index.php index.html index.htm;

......       
#取消location ~ .php$ 大括号前的注释(65~71)行
 65         location ~ \.php$ {
   
 66             root           /var/www/html;		#这里我修改为/var/www/html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;		#将/script..改为$document_root$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }
......       
/usr/local/nginx/sbin/nginx -s reload

[root@d46e5d7f7e13 ~]# rm -rf nginx-1.21.3
[root@d46e5d7f7e13 ~]# rm -rf nginx-1.21.3.tar.gz 

#下根目录下创建start.sh
cat >> start.sh <<EOF
#!/bin/bash
/usr/local/nginx/sbin/nginx
EOF
chmod +x start
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值