落尘之木
TO BE THE BEST!

Dockerfile Expose Example _verified_ File

Dockerfile Expose Example _verified_ File

COPY nginx.conf /etc/nginx/nginx.conf # Image EXPOSEs 3000, but we can run on different port internally docker run -p 8080:8080 -e PORT=8080 myapp Corresponding Dockerfile FROM node:18 ENV PORT=3000 # Default EXPOSE $PORT CMD ["sh", "-c", "npm start -- --port $PORT"] 10. Key Takeaways | Feature | Behavior | |---------|----------| | EXPOSE | Documentation only, no port publishing | | -p flag | Publishes port to specific host port | | -P flag | Publishes all EXPOSED ports to random ports | | Multiple ports | Can specify multiple EXPOSE lines | | TCP/UDP | Default TCP, specify /udp for UDP | | Port ranges | Supported by some runtimes (9000-9010) | Real-World Production Example FROM node:18-alpine AS frontend WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 8080 USER node Security: non-root user, specific port range CMD ["node", "server.js"]

: EXPOSE is metadata. Always use -p or -P when running containers to actually access the ports! dockerfile expose example

COPY package*.json ./ RUN npm install

COPY . . EXPOSE 8000/tcp # Main web application EXPOSE 8080/tcp # Admin interface EXPOSE 5432/tcp # Internal database (documentation only) UDP port example EXPOSE 53/udp # DNS service Port range (if supported by your container runtime) EXPOSE 9000-9010/tcp COPY nginx

CMD ["/myapp"] # View exposed ports from image docker image inspect myapp --format='json .Config.ExposedPorts' View actual published ports docker ps --format "table .Names\t.Ports" Detailed port mapping docker port mycontainer 7. Security & Best Practices # ✅ GOOD: Minimal exposure FROM node:18-alpine EXPOSE 3000 # Only what's necessary ❌ BAD: Over-exposing FROM node:18-alpine EXPOSE 1-65535 # Don't do this ✅ GOOD: Use environment variables FROM python:3.11 ENV APP_PORT=8000 EXPOSE $APP_PORT # Variable expansion works! ✅ GOOD: Document protocol EXPOSE 8000/tcp EXPOSE 53/udp 8. Advanced: HEALTHCHECK Integration FROM nginx:alpine EXPOSE 80 443 Health check using exposed ports HEALTHCHECK --interval=30s --timeout=3s CMD curl --fail http://localhost:80 || exit 1 EXPOSE 3000 8080 USER node Security: non-root user,

COPY . . EXPOSE 3000

COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt

赞(131) 赞赏
落尘之木公众号
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《Universal Xforce Autodesk 2019》
文章链接:https://www.luochenzhimu.com/archives/3144.html
免责声明:根据我国《计算机软件保护条例》第十七条规定:“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24小时之内删除,否则后果均由用户承担责任。

评论 1

评论前必须登录!

 

  1. #50
    dockerfile expose example
    UC Browser 11 UC Browser 11 iPhone iOS 11.3 iPhone iOS 11.3

    我就想知道那个x-force注册机在国外更新地址在那里,博主能给个地址吗?

    xiaobai8年前 (2018-04-26)

您的支持将鼓励我们继续创作!

支付宝扫一扫打赏

dockerfile expose example

微信扫一扫打赏

dockerfile expose example