博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS中部署Docker并配置Nginx
阅读量:6952 次
发布时间:2019-06-27

本文共 2306 字,大约阅读时间需要 7 分钟。

查看系统版本

[root@dc02 ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

查看内核版本

[root@dc02 ~]# uname -r

3.10.0-327.el7.x86_64

关闭selinux和防火墙

setenforce 0

sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config
systemctl disable firewalld.service
systemctl stop firewalld.service

下载docker

[root@dc02 ~]# yum install -y docker

替换国内加速器

[root@dc02 ~]# cat >/etc/docker/daemon.json <<EOF

{

"registry-mirrors": [""]
}
EOF
[root@dc02 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": [""]
}

加载生效

[root@dc02 ~]# systemctl daemon-reload

自启动

[root@dc02 ~]# systemctl enable docker

[root@dc02 ~]# systemctl start docker

查看状态

[root@dc02 ~]# systemctl status docker

下载官方centos镜像

[root@dc02 ~]# docker pull centos

Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
7dc0dca2b151: Pull complete
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for docker.io/centos:latest

查看所有下载镜像

[root@dc02 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB

启动并进入镜像

[root@dc02 ~]# docker run -it --name mynginx centos /bin/bash

安装常用命令

[root@9d76d200aae9 /]# yum install -y wget vim

[root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/CentOS-Base.repo
[root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/epel.repo

安装nginx

[root@9d76d200aae9 /]# yum install -y nginx

#docker默认禁止后台运行nginx
[root@9d76d200aae9 /]# vim /etc/nginx/nginx.conf
#在"user nginx;"下面加上一行"daemon off;"

检查nginx配置文件语法

[root@9d76d200aae9 /]# nginx -t

启动nginx

[root@9d76d200aae9 /]# nginx

启动后命令行是夯筑的,所以打开一个新的SSH连接查看镜像

启动后命令行是夯筑的,所以打开一个新的SSH连接查看镜像

[root@dc02 ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d76d200aae9 centos "/bin/bash" 14 minutes ago Up 14 minutes mynginx

提交镜像并查看

[root@dc02 ~]# docker commit -m "add new docker images" mynginx test/nginx:v1

sha256:5e28845136a33dc8e6175248086a90f9195dda4bdfc014a89b7ee32e37cc24d0
[root@dc02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/nginx v1 5e28845136a3 About a minute ago 420 MB
docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB

测试nginx连通性

[root@dc02 ~]# docker run -p 80:80 --name test_nginx 5e28845136a3 nginx

原文出处

转载于:https://blog.51cto.com/14210437/2354649

你可能感兴趣的文章
php网址显示excel表格内容
查看>>
HDU - 1874 畅通工程续(迪杰斯特拉)
查看>>
线段树 适合初学者
查看>>
go语言中的文件创建,写入,读取,删除
查看>>
jqGrid基本使用
查看>>
9.27作业
查看>>
驱动程序中使用SEH
查看>>
存储类(作用域、链接、存储时期)
查看>>
jsonp跨域请求
查看>>
OpenGL根据极坐标参数方程绘制心形线、螺旋线等图形
查看>>
通达OA2008从windows环境移植到linux部署手册
查看>>
CentOS6.5编译安装Nginx1.8.1+MySQL5.5.48+PHP5.2.17+xcache3.2+ZendOptimizer-3.3.9
查看>>
zabbix系列(五)zabbix3.0.4 探索主机Discovery自动发现主机详细图文教程
查看>>
利用jstack命令定位占用cpu高的java线程及具体错误代码信息
查看>>
枚举、模拟、递推
查看>>
PSD模板设计图转化为HTML模板的正确做法
查看>>
【C#】事件
查看>>
CF 672 div2 D
查看>>
字符串类dp的题目总结
查看>>
css 视图结构
查看>>