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
相关推荐
2501_920047036 小时前
k8s-ingress控制器
云原生·容器·kubernetes
K_i1346 小时前
Docker、容器、虚拟机到底是什么
docker·微服务·云原生·容器·kubernetes
Justin_198 小时前
nginx反向代理与缓存功能
运维·nginx
江湖有缘8 小时前
【Docker项目实战】使用Docker部署ShowDoc文档管理工具
java·docker·容器
XYiFfang8 小时前
【Docker】解决Docker中“exec format error”错误:架构不匹配的完整指南
docker·容器·架构
苹果醋310 小时前
数据结构其一 线性表
java·运维·spring boot·mysql·nginx
java干货10 小时前
我用Nginx做了负载均衡,还需要API网关吗?
运维·nginx·负载均衡
alenliu062111 小时前
在 Ubuntu22.04 进行envoy沙盒实验
docker·envoy·ubuntu22.04
致宏Rex1 天前
Docker 完整教程(3,4) | 网络与挂载
运维·docker·容器
不语n1 天前
Windows+Docker+AI开发板打造智能终端助手
python·docker·树莓派·香橙派·dify·ollama·ai开发板