欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos7 Docker离线部署nginx

程序员文章站 2022-05-27 16:38:20
...

1 环境信息

查看系统内核

[[email protected] /]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

2 虚拟机拉取镜像

此处资源获取在虚拟机中进行,完成后上传到服务器安装

2.1 拉取nginx镜像

[[email protected] /]# docker pull nginx

2.2 导出镜像

[[email protected] /]# docker save -o /opt/module/software/jingxiang/nginx.tar nginx:latest

3 服务器加载镜像

将提供的docker文件夹上传到服务器的 /opt/module/software/jingxiang 目录下

3.1 导入nginx镜像

[[email protected] /]# docker load -i /opt/module/software/jingxiang/nginx.tar
831c5620387f: Loading layer [==================================================>] 72.48 MB/72.48 MB
5fb987d2e54d: Loading layer [==================================================>] 57.67 MB/57.67 MB
4fc1aa8003a3: Loading layer [==================================================>] 3.584 kB/3.584 kB
Loaded image: docker.io/nginx:latest

3.2 创建容器

[[email protected] /]# docker run -p 80:80 --name nginx -d nginx

3.3 映射目录

[[email protected] home]# docker cp -a nginx:/etc/nginx/ /opt/module/env/nginx/conf
[[email protected] home]# docker stop nginx
[[email protected] home]# docker rm nginx

[[email protected] home]# docker run -p 80:80 --privileged=true --restart always --name nginx -v /opt/module/env/nginx/www:/www -v /opt/module/env/nginx/conf/:/etc/nginx/ -v /opt/module/env/nginx/logs:/var/log/nginx -v /opt/module/env/nginx/wwwlogs:/wwwlogs -d nginx

[[email protected] home]# docker restart nginx

3.4 配置nginx

[[email protected] ~]# vi /opt/module/env/nginx/conf/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        # root   /usr/share/nginx/html;
                root   /home/ftp/;
        index  index.html index.htm;
    }
...

3.5 启动服务

[[email protected] docker]# docker start nginx  

3.6 停止服务

[[email protected] docker]# docker stop nginx  

3.7 服务信息

服务      nginx
目录      /opt/module/env/nginx/conf/