小知识:Docker Compose部署Nginx的方法步骤

使用Docker Compose部署Nginx,创建dockercompose.yaml:

?
1
[root@192 ~]# vim dockercompose.yaml

输入以下内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: 3
services:
container_name: nginx
image: nginx
restart: always
ports:
– 8080:80
privileged: true
networks:
– mynginx
networks:
mynginx:
driver: bridge

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[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

关闭防火墙:

?
1
[root@192 ~]# systemctl stop firewalld

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

%小知识:Docker Compose部署Nginx的方法步骤-猿站网-插图

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

?
1
2
3
4
5
6
7
8
9
[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(防火墙需要先开启,不然会报错):

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

关闭服务:

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

启动服务:

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

到此这篇关于Docker Compose部署Nginx的方法步骤的文章就介绍到这了,更多相关Docker Compose部署Nginx内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_37960603/article/details/122907139

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Kubernetes安全加固的一些实用建议

2023-3-9 17:47:55

建站知识

小知识:Docker安装Nacos服务的实现

2023-3-9 18:02:45

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索