docker 安装nginx

查看redhat版本
cat /etc/redhat-release

docker 安装参照https://www.cnblogs.com/syrgdm/p/13200430.html
或者(deepin)参照https://www.cnblogs.com/syrgdm/p/12871952.html

拉取镜像
docker pull nginx
查询端口
netstat -ntlp
-a:列出系统中所有网络连接,包括已经连接的网络服务、监听的网络服务和 Socket 套接字;
-t:列出 TCP 数据;
-u:列出 UDF 数据;
-l:列出正在监听的网络服务(不包含已经连接的网络服务);
-n:用端口号来显示而不用服务名;
-p:列出该服务的进程 ID (PID);

查看拉取的镜像
docker images
启动镜像
sudo docker run --name nginx-test -p 8081:80 -d nginx

各参数
-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;

-d: 后台运行容器,并返回容器ID;

-i: 以交互模式运行容器,通常与 -t 同时使用;

-P: 随机端口映射,容器内部端口随机映射到主机的端口

-p: 指定端口映射,格式为:主机(宿主)端口:容器端口

-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;

--name="nginx-lb": 为容器指定一个名称;

--dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;

--dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;

-h "mars": 指定容器的hostname;

-e username="ritchie": 设置环境变量;

--env-file=[]: 从指定文件读入环境变量;

--cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;

-m :设置容器使用内存最大值;
--net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;

--link=[]: 添加链接到另一个容器;

--expose=[]: 开放一个端口或一组端口;

--volume , -v: 绑定一个卷

找到配置文件
etc/nginx/nginx.conf
不能直接使用vi nginx.conf
apt-get update 完成后
apt-get install vim
然后再打开vi nginx.conf

mkdir -p /server/nginx/www
mkdir -p /server/nginx/log
mkdir -p /server/nginx/conf
docker run --name nginxtest -p 8089:80 -d nginx
docker ps查看容器id
将测试容器中的配置文件拷贝到正式的nginx的cong目录下
docker cp 容器id :etc/nginx/nginx.conf ~/server/nginx/conf

先停掉之前测试的nginx容器
docker stop 容器id
docker rm 容器id
执行

docker run -d -p 8082:80 --name nginx1 -v ~/server/nginx/www:/usr/share/nginx/html -v ~/sever/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/server/nginx/logs:/var/log/nginx nginx

Nginx基本命令:
nginx -s quit 优雅停止nginx,有连接时会等连接请求完成再杀死worker进程
nginx -s reload 优雅重启,并重新载入配置文件nginx.conf
nginx -s reopen 重新打开日志文件,一般用于切割日志
nginx -v 查看版本
nginx -t 检查nginx的配置文件
nginx -h 查看帮助信息
 nginx -V 详细版本信息,包括编译参数
nginx -c filename 指定配置文件
nginx -c /etc/nginx/nginx.conf 重启nginx
-c /etc/nginx/nginx.conf 更新配置文件

posted @ 2020-06-29 11:33  岁月染过的梦  阅读(342)  评论(0)    收藏  举报