搜索
docker search nginx
拉取鏡像
會獲取最新的nginx鏡像
docker pull nginx
查看鏡像
docker images nginx
運行容器
1. 創建外部目錄nginx_temp
mkdir -p ~/nginx_temp/www ~/nginx_temp/logs ~/nginx_temp/conf/conf.d
www 目錄將映射爲 nginx 容器配置的虛擬目錄
logs 目錄將映射爲 nginx 容器的日誌目錄
conf 目錄裏的配置文件將映射爲 nginx 容器的配置文件
2. 執行
docker run -d -p 81:80 --name nginx-server-1 \
-v ~/nginx_temp/www:/usr/share/nginx/html \
-v ~/nginx_temp/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
-v ~/nginx_temp/conf/nginx.conf:/etc/nginx/nginx.conf \
-v ~/nginx_temp/logs:/var/log/nginx nginx
-p 81:80 將本機的81端口映射到容器的80端口
–name nginx-server-1 將容器命名爲 nginx-server-1
-v 將本機目錄掛載到容器目錄上
測試容器
1. 進入www目錄
cd ~/nginx_temp/www
創建 index.html 文件,內容如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> 標題</title>
</head>
<body>
<h1>第一行</h1>
</body>
</html>
2. 測試端口
在瀏覽器輸入 localhost:81
其它
1. 重新載入nginx
如果修改配置後需要重新載入nginx,可以使用命令
docker kill -s HUP container-name