[英]How do I build a custom nginx:alpine based container listening on port other than 80?
我需要一個基於nginx:alpine的Docker容器,可從端口8080提供HTTP內容,但默認情況下nginx:alpine會在端口80上進行偵聽。
構建自定義容器時如何更改端口?
選項1(推薦):設置新的配置文件
創建具有以下內容的本地default.conf *文件:
server {
listen 8080;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
*在端口8080以外,請自定義上述內容以滿足您的需求
將default.conf復制到自定義容器[Dockerfile]:
FROM nginx:alpine
## Copy a new configuration file setting listen port to 8080
COPY ./default.conf /etc/nginx/conf.d/
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
選項2:更改nginx的默認配置[Dockerfile]
FROM nginx:alpine
## Make a copy of default configuration file and change listen port to 8080
RUN cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.orig && \
sed -i 's/listen[[:space:]]*80;/listen 8080;/g' /etc/nginx/conf.d/default.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
當然,對原始配置進行備份是可選的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.