首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub

Summer

运维界的小白
首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub
  • Docker

    • yum方式在线安装
    • 离线安装
    • docker安装mysql
    • docker安装DockerCompose
    • docker安装wordpress
    • docker安装redis单节点
    • docker安装easy-mock
    • docker安装oracle11g
    • docker安装elasticsearch单节点
    • 纯docker化centos7单机环境
    • docker安装nginx
      • 拉取镜像
      • 启动
      • 自定义nginx
    • docker安装Greenplum
    • docker安装Grafana
    • docker安装prometheus
  • Zabbix

  • Elasticsearch

  • K8s

  • Mysql

  • Redis

  • Nginx

  • Prometheus

  • 安装
  • Docker
summer
2020-11-27

docker安装nginx

docker部署nginx非常简单 难的是如何定义nginx.conf与部署html下的前端文件

# 拉取镜像

[root@localhost ~]# docker pull nginx:1.14.0
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
nginx                1.14.0              ecc98fc2f376        2 years ago         109MB
1
2
3
4

# 启动

[root@localhost ~]# docker run --name nginx-test -p 8080:80 -d nginx:1.14.0
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
8657715d04a5        nginx:1.14.0        "nginx -g 'daemon of…"   5 hours ago         Up 45 minutes       0.0.0.0:8080->80/tcp   nginx-test
1
2
3
4
  • 这时候访问本机ip:8080 就能看到熟悉的Welcome to nginx!

# 自定义nginx

  1. 进入容器
[root@localhost ~]# docker exec -it 8657715d04a5 /bin/bash
root@8657715d04a5:/# ls
bin  boot  dev	etc  home  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var
root@8657715d04a5:/# 
1
2
3
4
  1. 查找对应路径
root@8657715d04a5:/# find / -name nginx
/etc/default/nginx
/etc/init.d/nginx
/etc/logrotate.d/nginx
/etc/nginx # 配置文件路径
/usr/lib/nginx
/usr/sbin/nginx # 启停
/usr/share/doc/nginx 
/usr/share/nginx # 默认html存放路径
/var/cache/nginx 
/var/log/nginx  # 默认日志文件      
root@8657715d04a5:/# find / -name nginx.conf
/etc/nginx/nginx.conf  # 编辑该配置文件哦
1
2
3
4
5
6
7
8
9
10
11
12
13
  1. 复制前端文件到容器中
[root@localhost ~]# docker cp  /home/summer/nginx/html 8657715d04a5:/usr/share/nginx/html
1
  1. 处理默认配置
root@8657715d04a5:/etc/nginx/conf.d# pwd
/etc/nginx/conf.d
root@8657715d04a5:/etc/nginx/conf.d# mv default.conf default
1
2
3
  1. 编辑定制nginx.conf
root@8657715d04a5:/# vim /etc/nginx/nginx.conf
1
  1. 重新加载
root@8657715d04a5:/usr/sbin# ./nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@8657715d04a5:/usr/sbin# ./nginx -s reload
1
2
3
4
  1. 保存定制的镜像
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
8657715d04a5        nginx:1.14.0        "nginx -g 'daemon of…"   5 hours ago         Up 31 minutes       0.0.0.0:8080->80/tcp   nginx-test
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
summer/centos7-ssh   latest              1c0967200c5d        8 days ago          346MB
centos               centos7.5.1804      cf49811e3cdb        20 months ago       200MB
nginx                1.14.0              ecc98fc2f376        2 years ago         109MB
[root@localhost ~]# docker commit 8657715d04a5 summer/nginx-k8s
sha256:92e3cc68a48d7e626cbf122dfff9dbfa35de50153a7f9aace0295f9856c708c9
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
summer/nginx-k8s     latest              92e3cc68a48d        12 seconds ago      479MB
summer/centos7-ssh   latest              1c0967200c5d        8 days ago          346MB
centos               centos7.5.1804      cf49811e3cdb        20 months ago       200MB
nginx                1.14.0              ecc98fc2f376        2 years ago         109MB
[root@localhost ~]# docker save -o nginx-k8s.tar summer/nginx-k8s:latest
[root@localhost ~]# ll
-rw-------  1 root root 495302656 Nov 27 22:43 nginx-k8s.tar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  1. 装载镜像
docker load -i nginx-k8s.tar
1
纯docker化centos7单机环境
docker安装Greenplum

← 纯docker化centos7单机环境 docker安装Greenplum→

最近更新
01
redis持久化
12-08
02
redis为什么这么快
12-08
03
redis的优缺点
12-08
更多文章>
Theme by Vdoing | Copyright © 2019-2020 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式