首页 > 系统相关 >Nginx:Docker Compose部署Nginx

Nginx:Docker Compose部署Nginx

时间:2022-11-09 20:31:41浏览次数:35  
标签:Compose nginx 192 Nginx sh entrypoint Docker root docker


使用​​Docker Compose​​​部署​​Nginx​​​,创建​​docker-compose.yaml​​:

[root@192 ~]# vim docker-compose.yaml

输入以下内容:

version: '3'
services:
nginx:
container_name: nginx
image: nginx
restart: always
ports:
- 8080:80
privileged: true
networks:
- mynginx

networks:
mynginx:
driver: bridge

基于​​docker-compose.yaml​​创建并启动容器:

[root@192 ~]# docker compose up
[+] Running 7/7
⠿ nginx Pulled 20.5s
⠿ 5eb5b503b376 Pull complete 12.6s
⠿ 1ae07ab881bd Pull complete 14.8s
⠿ 78091884b7be Pull complete 14.9s
⠿ 091c283c6a66 Pull complete 15.0s
⠿ 55de5851019b Pull complete 15.1s
⠿ b559bad762be Pull complete 15.2s
[+] Running 2/2
⠿ Network root_mynginx Created 0.3s
⠿ Container nginx Created 1.8s
Attaching to nginx
nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
nginx | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx | 2022/02/13 03:43:39 [notice] 1#1: using the "epoll" event method
nginx | 2022/02/13 03:43:39 [notice] 1#1: nginx/1.21.6
nginx | 2022/02/13 03:43:39 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
nginx | 2022/02/13 03:43:39 [notice] 1#1: OS: Linux 3.10.0-1160.el7.x86_64
nginx | 2022/02/13 03:43:39 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx | 2022/02/13 03:43:39 [notice] 1#1: start worker processes
nginx | 2022/02/13 03:43:39 [notice] 1#1: start worker process 31

关闭防火墙:

[root@192 ~]# systemctl stop firewalld

本地浏览器可以访问,说明​​Nginx​​部署成功了。

Nginx:Docker Compose部署Nginx_linux


​Docker​​​也可以查到​​Docker Compose​​拉取的镜像和创建的容器。

[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c316d5a335a5 2 weeks ago 142MB
lazyteam/lazydocker latest 3b572700e20d 10 months ago 69.9MB
portainer/portainer latest 580c0e4e98b0 11 months ago 79.1MB
openjdk 8-jdk-alpine a3562aa0b991 2 years ago 105MB
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e31945577104 nginx "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp nginx

后台​​up​​(防火墙需要先开启,不然会报错):

[root@192 ~]# systemctl start firewalld
[root@192 ~]# docker compose up -d
[+] Running 1/1
⠿ Container nginx Started

关闭服务:

[root@192 ~]# docker compose stop nginx
[+] Running 1/1
⠿ Container nginx Stopped

启动服务:

[root@192 ~]# docker compose start nginx
[+] Running 1/1
⠿ Container nginx Started


标签:Compose,nginx,192,Nginx,sh,entrypoint,Docker,root,docker
From: https://blog.51cto.com/u_15870611/5838738

相关文章

  • Nginx分发算法实现
    1、基于轮询分发:根据请求流量均匀分发到后端服务器upstreamweb{serverserver1;serverserver2;}server{listen80;server_namelocalhost;......
  • Nginx分发算法介绍
    分发算法:如何将用户请求按照一定的规律分发给业务服务器。主要分为Nginx集群默认算法和基于请求头分发算法。nginx的upstream目前支持4种方式的分配:1)轮询(默认)  每......
  • Nginx配置分发器
    本文章以nginx作为分发器,httpd作为后端服务器,nginx负责将请求流量分发到httpd节点。1、执行nginx安装脚本(往期文章有)shnginx_install2、切换到nginx配置文件目录cd......
  • Nginx集群介绍
    一、Nginx集群组成组成要素:1)VIP:给分发器的一个虚IP2)分发器:nginx3)数据服务器:web服务器二、nginx集群原理在Nginx集群中Nginx扮演的角色是分发器。主要任务是接受请求......
  • docker.sock: connect: permission denied 解决
    问题描述xjun@DESKTOP-L2R4GKN:~$dockerrun-ithello-worlddocker:GotpermissiondeniedwhiletryingtoconnecttotheDockerdaemonsocketatunix:///var/run/......
  • Shell脚本安装Nginx
    #!/bin/bashnginx_pkg='nginx-1.19.3.tar.gz'nginx_prefix=/usr/local/nginxhtml=/var/nginxlog=/var/log/nginxcheck13(){[$UID-ne0]&&echo"needto......
  • Docker:安装Docker Compose
    ​​DockerCompose​​​是一个在​​Docker​​​上运行多容器应用程序的工具,使用​​Compose​​​文件格式定义。​​Compose​​文件用于定义组成应用程序的一个或多个......
  • Nginx 优化与防盗链
    一、隐藏版本号1、隐藏版本号的操作步骤可以使用Fiddler工具抓取数据包,查看Nginx版本,也可以在CentOS中使用命令 curl-Ihttp://192.168.160.60显示响应报文首部信......
  • Nginx:代理FastDFS实现文件访问
    搭建​​FastDFS​​分布式文件系统参考下面这篇博客:​​分布式:搭建FastDFS分布式文件系统​​安装fastdfs-nginx-module安装​​fastdfs-nginx-module​​​也是只在​​st......
  • Docker - Docker Image及Image命令详解
    Docker-DockerImage及Image命令详解什么是镜像(Image)Docker镜像(DockerImage)就是一个只读的模板。比如,一个镜像可以包含一个完整的Ubuntu操作系统环境。镜像可以用来创建D......