Docker Compose部署Nginx的方法步驟
使用Docker Compose部署Nginx,創(chuàng)建docker-compose.yaml:
[root@192 ~]# vim docker-compose.yaml
輸入以下內(nèi)容:
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創(chuàng)建并啟動容器:
[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
關(guān)閉防火墻:
[root@192 ~]# systemctl stop firewalld
本地瀏覽器可以訪問,說明Nginx部署成功了。

Docker也可以查到Docker Compose拉取的鏡像和創(chuàng)建的容器。
[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
關(guān)閉服務(wù):
[root@192 ~]# docker compose stop nginx [+] Running 1/1 ? Container nginx Stopped
啟動服務(wù):
[root@192 ~]# docker compose start nginx [+] Running 1/1 ? Container nginx Started
到此這篇關(guān)于Docker Compose部署Nginx的方法步驟的文章就介紹到這了,更多相關(guān)Docker Compose部署Nginx內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker部署Nginx設(shè)置環(huán)境變量的實(shí)現(xiàn)步驟
本文主要介紹了Docker部署Nginx設(shè)置環(huán)境變量的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
docker部署Zlm服務(wù)的實(shí)現(xiàn)
本文主要介紹了docker部署Zlm服務(wù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-03-03
在Centos7中安裝Docker1.12的詳細(xì)教程
本篇文章主要介紹了在Centos7中安裝Docker1.12的詳細(xì)教程。具有一定的參考價值,有興趣的可以了解一下。2017-02-02
yum下載rpm以及相關(guān)依賴的方式離線安裝docker
今天小編就為大家分享一篇關(guān)于yum下載rpm以及相關(guān)依賴的方式離線安裝docker,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12
詳解Dockerfile創(chuàng)建自定義Docker鏡像以及CMD與ENTRYPOINT指令的比較
這篇文章主要介紹了詳解Dockerfile創(chuàng)建自定義Docker鏡像以及CMD與ENTRYPOINT指令的比較,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

