Rumah  >  Artikel  >  Operasi dan penyelenggaraan  >  Pengerahan CentOS7 Docker Nginx dan menjalankan analisis contoh

Pengerahan CentOS7 Docker Nginx dan menjalankan analisis contoh

WBOY
WBOYke hadapan
2023-05-14 17:10:15862semak imbas

1. Penyediaan sumber

fail dockerfile

# "ported" by adam miller <maxamillion@fedoraproject.org> from 
#  https://github.com/fedora-cloud/fedora-dockerfiles 
# 
# originally written for fedora-dockerfiles by 
#  scollier <scollier@redhat.com> 
 
from centos:centos7 
maintainer the centos project <cloud-ops@centos.org> 
 
run yum -y update; yum clean all 
run yum -y install epel-release tar ; yum clean all 
run yum -y install nginx ; yum clean all 
add nginx.conf /opt/deploy/nginx/nginx.conf 
run echo "daemon off;" >> /opt/deploy/nginx/nginx.conf 
#run curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ 
#  | tar -xz -c /usr/local/nginx/html \ 
#  --strip-components=1 
#run sed -i -e &#39;s/apache/nginx/g&#39; -e &#39;/apache_pb.gif/d&#39; \  
#  /usr/local/nginx/html/index.html 
 
expose 80 
 
#cmd [ "/usr/local/nginx/sbin" ]

Nota: Laluan perlu wujud pada sistem dan sepadan dengan

fail nginx.conf

# for more information on configuration, see: 
#  * official english documentation: http://nginx.org/en/docs/ 
#  * official russian documentation: http://nginx.org/ru/docs/ 
 
user nginx; 
worker_processes 1; 
 
error_log /usr/logs/nginx/error.log; 
#error_log /var/log/nginx/error.log notice; 
#error_log /var/log/nginx/error.log info; 
 
pid    /run/nginx.pid; 
 
 
events { 
  worker_connections 1024; 
} 
 
 
http { 
  include    mime.types; 
  default_type application/octet-stream; 
 
  log_format main &#39;$remote_addr - $remote_user [$time_local] "$request" &#39; 
           &#39;$status $body_bytes_sent "$http_referer" &#39; 
           &#39;"$http_user_agent" "$http_x_forwarded_for"&#39;; 
 
  access_log /usr/logs/nginx/access.log main; 
 
  sendfile    on; 
  #tcp_nopush   on; 
 
  #keepalive_timeout 0; 
  keepalive_timeout 65; 
 
  #gzip on; 
 
  # load modular configuration files from the /etc/nginx/conf.d directory. 
  # see http://nginx.org/en/docs/ngx_core_module.html#include 
  # for more information. 
  #include /etc/nginx/conf.d/*.conf; 
 
  index  index.html index.htm; 
 
  server { 
    listen    80; 
    server_name localhost; 
    root     /usr/share/nginx/html; 
 
    #charset koi8-r; 
 
    #access_log /var/log/nginx/host.access.log main; 
 
    location / { 
      autoindex on; 
    } 
 
    # redirect server error pages to the static page /40x.html 
    # 
    error_page 404       /404.html; 
    location = /40x.html { 
    } 
 
    # redirect server error pages to the static page /50x.html 
    # 
    error_page  500 502 503 504 /50x.html; 
    location = /50x.html { 
    } 
 
    # proxy the php scripts to apache listening on 127.0.0.1:80 
    # 
    #location ~ \.php$ { 
    #  proxy_pass  http://127.0.0.1; 
    #} 
 
    # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 
    # 
    #location ~ \.php$ { 
    #  root      html; 
    #  fastcgi_pass  127.0.0.1:9000; 
    #  fastcgi_index index.php; 
    #  fastcgi_param script_filename /scripts$fastcgi_script_name; 
    #  include    fastcgi_params; 
    #} 
 
    # deny access to .htaccess files, if apache&#39;s document root 
    # concurs with nginx&#39;s one 
    # 
    #location ~ /\.ht { 
    #  deny all; 
    #} 
  } 
 
 
  # another virtual host using mix of ip-, name-, and port-based configuration 
  # 
  #server { 
  #  listen    8000; 
  #  listen    somename:8080; 
  #  server_name somename alias another.alias; 
  #  root     html; 
 
  #  location / { 
  #  } 
  #} 
 
 
  # https server 
  # 
  #server { 
  #  listen    443; 
  #  server_name localhost; 
  #  root     html; 
 
  #  ssl         on; 
  #  ssl_certificate   cert.pem; 
  #  ssl_certificate_key cert.key; 
 
  #  ssl_session_timeout 5m; 
 
  #  ssl_protocols sslv2 sslv3 tlsv1; 
  #  ssl_ciphers high:!anull:!md5; 
  #  ssl_prefer_server_ciphers  on; 
 
  #  location / { 
  #  } 
  #} 
 
}

Nota: Laluan perlu wujud pada sistem dan sepadan dengan

2. Jalankan arahan imej binaan

Salin kod Kod itu ialah seperti berikut:


[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 . >

3. Semak sama ada imej berjaya dipasang dan dibina imej docker

CentOS7 Docker Nginx部署及运行实例分析

4. Buat larian docker kontena -i -t -d -p 192.168.32.129:81:80 os7/nginx / bin/bash

CentOS7 Docker Nginx部署及运行实例分析

Nota: Jika alamat IP ialah 192.168.32.129, anda perlu menambah


192.168.32.129 localhost


5 Periksa sama ada bekas itu berjaya dibuat dan mulakan docker ps


6. . Uji sama ada curl http://192.168.32.129:81 berjaya diakses

CentOS7 Docker Nginx部署及运行实例分析

Sambungan yang ditolak muncul, jadi apa yang perlu saya lakukan? Jika ada penyelesaian, mari kita masukkan dahulu bekas

7 Masukkan bekas docker exec -i -t small_hodgkin /bin/sh CentOS7 Docker Nginx部署及运行实例分析

8. Kemudian Laksanakan di dalam bekas (hanya masukkan terus)

CentOS7 Docker Nginx部署及运行实例分析nginx


9 Jalankan curl http://192.168.32.129:81

di luar. bekas itu >

Berjaya.

10 Pergi ke luar mesin maya dan aksesnya melalui penyemak imbas CentOS7 Docker Nginx部署及运行实例分析

Atas ialah kandungan terperinci Pengerahan CentOS7 Docker Nginx dan menjalankan analisis contoh. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:yisu.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam