Docker 自動運行Nginx容器


Dockerfile文件如下:

FROM ubuntu #基礎鏡像
RUN apt-get update #更新apt
RUN apt-get -y install nginx #安裝nginx
VOLUME ["data"] #可選,掛載目錄
EXPOSE 80 #暴露80端口
CMD nginx -g "daemon off;" #后台運行nginx命令,在運行容器時執行

構建鏡像:
sudo docker build -t ubun/nginx .
指定名稱為ubun/nginx,在當前目錄下搜索Dockerfile

運行容器:
docker run -d --name nginx -p 80:80 ubun/nginx
綁定本地80端口到容器的80端口

測試:
curl 127.0.0.1

若返回以下內容則是成功:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM