Docker:部署Nginx

目录


一、搜索镜像

linux 复制代码
docker search docker-0.unsee.tech/nginx:1.14.2

二、拉取镜像

linux 复制代码
docker pull nginx:1.14.2

三、创建本地挂载目录

linux 复制代码
mkdir -p /root/nginx/{conf,html,log} 

四、编写nginx配置文件

需要注意的是,这里的root目录一定要写/usr/share/nginx/html否则找不到

conf 复制代码
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  192.168.98.129;
		charset utf-8;

		location / {
			root   /usr/share/nginx/html;
            index  index.html index.htm;

			try_files $uri $uri/ /index.html;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

五、启动容器

linux 复制代码
docker run -d --name nginx -p 80:80 \
--restart=unless-stopped \
-v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /root/nginx/html:/usr/share/nginx/html \
-v /root/nginx/log:/var/log/nginx \
--network 网络名称 \
nginx:1.14.2
相关推荐
虎头金猫17 小时前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
还是大剑师兰特18 小时前
解决nginx错误:http://localhost:7000正常,http://localhost:7000/map 报错404
nginx·大剑师
分布式存储与RustFS18 小时前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
玉&心20 小时前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing20 小时前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
赵文宇(温玉)20 小时前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang21 小时前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特21 小时前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe21 小时前
docker常见命令
docker
正经教主1 天前
【FDE系列】阶段2:Day 43:Docker Compose — 多容器一键编排
人工智能·docker·fde