好物优选点击查看详情 京东购买

暂无内容

每天一博–第三天 安装docker及通过docker部署nginx [ dockerfile方式 ]

不同的操作系统,使用的安装工具不同,我用的是manjaro,arch的衍生版本,使用的是pacman,Ubuntu的是apt-get,Centos/Redhat的是yum,但是安装方式不尽相同。

 sudo pacman -Syy docker sudo systemctl enable docker sudo systemctl start docker 

如果是测试环境中,安装docker前可以将selinux,firewalld关闭,正式环境中需要将docker服务在firewalld的zone–service中开启,并开启相应的端口。

Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。

本文主要讲解如何通过dockerfile创建docker container,将不通过docker-compose进行创建管理

 sudo curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` >/usr/local/bin/docker-compose  docker-compose -v 
 sudo pacman -S python-pip  mkdir .pip vim .pip/pip.ini [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn  sudo pip install -U/--upgrade pip  sudo pip install docker-compose  docker-compose -v 
pip其他镜像源地址 (1)阿里云 http://mirrors.aliyun.com/pypi/simple/ (2)豆瓣http://pypi.douban.com/simple/ (3)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ (4)华中科技大学http://pypi.hustunique.com/ 

下载nginx,可以到nginx.org上看一下,上面有每个版本的详细介绍,根据自身需求进行下载

mkdir -p /data/docker/nginx wget -P /data/docker/nginx http://nginx.org/download/nginx-1.17.5.tar.gz cd /data/docker/nginx tar zxvf nginx-1.17.5.tar.gz 
 mkdir -p /data/docker/nginx/volume  cd /data/docker/nginx  cat Dockerfile FROM centos MAINTAINER superjay09 ADD nginx-1.17.5.tar.gz /usr/local/src  RUN /bin/cp -r /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone RUN yum -y update RUN yum -y install gcc gcc-c++ vim make autoconf openssl openssl-devel RUN yum -y install pcre pcre-devel zlib zlib-devel libtool net-tools RUN useradd -s /sbin/nologin -M www  ONBUILD VOLUME ["/data/docker/nginx/volume"] WORKDIR /usr/local/src/nginx-1.17.5 RUN ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module && make && make install ENV PATH /usr/local/nginx/sbin:$PATH EXPOSE 80 ENTRYPOINT ["nginx"] CMD ["-g"] 
 docker build -t myweb-nginx:v1 .   docker run -itd -p 80:80 --name myweb-nginx1 myweb-nginx:v1 -g "daemon off;"   docker network create --driver overlay --subnet 172.16.0.0/24 web-overlay-network  docker init --adversite-add=192.168.0.128   docker server create --name myweb-nginx1 --network web-overlay-network --publish 80:80 myweb-nginx:v1 -g "daemon off;"  docker server create --name myweb-nginx2 --network web-overlay-network --publish 90:80 myweb-nginx:v1 -g "daemon off;"  docker service ls ID NAME MODE REPLICAS IMAGE PORTS 10ht1mbblstb myweb-nginx1 replicated 1/1 myweb-nginx:v1 *:80->80/tcp 9fhs78s12h3s myweb-nginx2 replicated 1/1 myweb-nginx:v1 *:90->80/tcp 
  docker network ls NETWORK ID NAME DRIVER SCOPE fe1421b20f7b bridge bridge local a0f113ecce4a data_default bridge local 2bc7f78ebb1c docker_gwbridge bridge local 61027189820b host host local v16qrysdnwsc ingress overlay swarm wls3lagjyp0y my-overlay-network overlay swarm 9e436754a07c none null local 
  docker exec 891662db0458 ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450 inet 10.255.0.4 netmask 255.255.0.0 broadcast 10.255.255.255 ether 02:42:0a:ff:00:04 txqueuelen 0 (Ethernet) 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 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450 inet 172.16.0.3 netmask 255.255.255.0 broadcast 172.16.0.255 ether 02:42:ac:10:00:03 txqueuelen 0 (Ethernet) 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 eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.19.0.3 netmask 255.255.0.0 broadcast 172.19.255.255 ether 02:42:ac:13:00:03 txqueuelen 0 (Ethernet) RX packets 305 bytes 58340 (56.9 KiB) 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 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 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 
  docker exec dfc6eea2becf ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450 inet 10.255.0.3 netmask 255.255.0.0 broadcast 10.255.255.255 ether 02:42:0a:ff:00:03 txqueuelen 0 (Ethernet) 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 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450 inet 172.16.0.2 netmask 255.255.255.0 broadcast 172.16.0.255 ether 02:42:ac:10:00:02 txqueuelen 0 (Ethernet) 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 eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.19.0.4 netmask 255.255.0.0 broadcast 172.19.255.255 ether 02:42:ac:13:00:04 txqueuelen 0 (Ethernet) RX packets 313 bytes 60044 (58.6 KiB) 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 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 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 
  docker exec 891662db0458 ping myweb-nginx1 PING myweb-nginx1 (172.16.0.8) 56(84) bytes of data. 64 bytes from 172.16.0.8 (172.16.0.8): icmp_seq=1 ttl=64 time=0.197 ms 64 bytes from 172.16.0.8 (172.16.0.8): icmp_seq=2 ttl=64 time=0.110 ms 64 bytes from 172.16.0.8 (172.16.0.8): icmp_seq=3 ttl=64 time=0.111 ms 

至此,大功告成

原文链接:https://blog.csdn.net/weixin_42543813/article/details/103021841

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享