centos7下使用docker安裝nginx

2022-05-04 14:45:12 字數 1819 閱讀 6824

需要環境docker,此處不做介紹。

1. docker拉取官方nginx映象

docker pull nginx

[root@wsyhrq171356 ~]# docker images

repository tag image id created size

nginx latest 62f816a209e6 8 days ago 109mb

3. 建立目錄 nginx/html、nginx/conf、nginx/logs, 用於存放後面靜態頁面、配置檔案、日誌檔案的相關東西。

[root@wsyhrq171356 /]# mkdir -p /nginx/html/ /nginx/conf/ /nginx/logs/
4. 建立配置檔案nginx.conf

[root@wsyhrq171356 /]# vi /nginx/conf/nginx.conf
貼上入如下內容:

5. 建立配置檔案mime.types

[root@wsyhrq171356 /]# vi /nginx/conf/mime.types
貼上入如下內容:

types
6. 新建靜態頁面檔案index.html用於測試nginx啟動狀態:

[root@wsyhrq171356 /]# vi /nginx/html/index.html
內容如下:

7. 使用 nginx 映象執行容器

[root@wsyhrq171356 /]# docker run -d -p 80:80 --name nginx -v /nginx/html:/usr/share/nginx/html -v /nginx/conf:/etc/nginx -v /nginx/logs:/var/log/nginx nginx
命令說明:

8. 檢視容器啟動情況

[root@wsyhrq171356 /]# docker ps

container id image command created status ports names

8892da7cdcfc nginx "nginx -g 'daemon of…" about an hour ago up 39 minutes 0.0.0.0:80->80/tcp nginx

9. 通過瀏覽器訪問如下,完成nginx安裝

centos7以yum方式安裝docker

yum包更新到最新 sudo yum update 設定yum源為阿里雲 sudo yum config manager add repo 安裝docker sudo yum install docker ce 檢視docker版本 docker v 設定ustc的映象 ustc docker mi...

CentOS 7 安裝配置Git和Docker

git安裝配置yum命令一鍵安裝 yum y install git配置 配置乙個用於提交 的使用者,輸入指令 git config global user.name your name 同時配置乙個使用者的郵箱,輸入命令 git config global user.email email exa...

CentOS 7下FirewallD使用簡介

學習apache安裝的時候需要開啟80埠,由於centos 7版本以後預設使用firewalld後,網上關於iptables的設定方法已經不管用了,想著反正iptable也不會用,索性直接搬官方文件,學習firewalld了,好像比iptables要簡單點了。1 firewalld簡介 firewa...