Centos7 Docker离线部署nginx

1 环境信息

查看系统内核

[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

2 虚拟机拉取镜像

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

2.1 拉取nginx镜像

[root@localhost /]# docker pull nginx

2.2 导出镜像

[root@localhost /]# docker save -o /opt/module/software/jingxiang/nginx.tar nginx:latest

3 服务器加载镜像

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

3.1 导入nginx镜像

[root@localhost /]# 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 创建容器

[root@localhost /]# docker run -p 80:80 --name nginx -d nginx

3.3 映射目录

[root@localhost home]# docker cp -a nginx:/etc/nginx/ /opt/module/env/nginx/conf
[root@localhost home]# docker stop nginx
[root@localhost home]# docker rm nginx

[root@localhost 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

[root@localhost home]# docker restart nginx

3.4 配置nginx

[root@localhost ~]# 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 启动服务

[root@localhost docker]# docker start nginx  

3.6 停止服务

[root@localhost docker]# docker stop nginx  

3.7 服务信息

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

4 相关资源

  • 下载地址 https://download.csdn.net/download/qq_15769939/14886797
  • 博文不易,辛苦各位猿友点个关注和赞,然后评论区留邮箱,看到后第一时间发

你可能感兴趣的:(Centos7,Docker,docker,nginx,centos)