docker 运行容器,安装Nginx
###########################################运行容器#安装Nginx#搜索、下载镜像docker search nginxdocker pull nginxdocker images nginx#运行容器mynginxdocker run -p 80:80 --name mynginx -d nginx#查看端口netstat -antp|grep 80#访问测试curl 127.0.0.1#外部浏览器访问ip正常,部署成功#进入Nginx容器docker exec -it mynginx /bin/sh#退出容器 exitCtrl+d #快捷键#列出容器docker ps -a#删除容器docker rm mynginx##########################################运行Nginx部署网站###########################################接下来思考问题:#Nginx配置、查看日志、部署网站#需要把外部的目录或文件映射到docker容器#创建目录Ngdir=/www/docker/nginxmkdir -p $Ngdir/{www,log,conf/conf.d}#创建配置(采用默认配置去注释)echo '#man configuser nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events {worker_connections 1024;}http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;sendfile on;keepalive_timeout 65;include /etc/nginx/conf.d/*.conf;}'>$Ngdir/conf/nginx.conf#echo '#nginxserver {listen 80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;}error_page 500 502 503 504 404 /50x.html;location = /50x.html {root /usr/share/nginx/html;}}'>$Ngdir/conf/conf.d/default.conf#htmlecho 'Welcome to nginx!'>$Ngdir/www/index.htmlecho 'error_page 500 502 503 504 404'>$Ngdir/www/50x.html#使用nginx镜像,创建容器mynginxdocker run -p 80:80 --name mynginx -v $Ngdir/conf/nginx.conf:/etc/nginx/nginx.conf:ro -v $Ngdir/conf/conf.d:/etc/nginx/conf.d:ro -v $Ngdir/www:/usr/share/nginx/html:rw -v $Ngdir/log:/var/log/nginx:rw -d nginx#测试html内容curl 127.0.0.1curl 127.0.0.1/123#查看error.logcat $Ngdir/log/error.log#测试成功 ^_^# 参数说明:# -p 80:80:本地80端口:映射docker容器80端口# -v $Ngdir/log:/var/log/nginx 主机log目录挂载到容器log/nginx
赞 (0)