如何创建适合应用的 Dockerfile。
Dockerfile 草案必须适合应用运行时和构建流程。检查依赖安装、暴露端口和进入镜像的文件。
按任务需求调整流程。
说明运行时、构建产物和启动命令,再起草只包含所需文件的镜像。审查依赖安装、用户和端口假设,并在预期环境中测试构建。
- 你需要提供什么
- 应用技术栈和部署要求。
- 你会得到什么
- 附依赖与假设的 Dockerfile 草案。
查看输入和结果。
演示用输入和输出 · 教学示例,并非 WebAct 实时运行结果
示例 个输入项
Draft a Dockerfile for a plain Node 24 service with package-lock.json, npm start, no build step, port 3000 and server binding to 0.0.0.0. Only source file is server.js; runtime needs no filesystem writes.
完整示例
FROM node:24-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci --omit=dev COPY server.js ./server.js ENV NODE_ENV=production USER node EXPOSE 3000 CMD ["npm", "start"] Build and test in your environment. Only the declared runtime files enter this image. EXPOSE documents the port; publish it explicitly when running the container. A production release should pin a reviewed image digest.
将这份输入载入提示词,再复制到 WebAct 中尝试任务。实际结果可能与示例不同。
决策与问题排查。
EXPOSE 会自动发布容器端口吗?
它记录预期端口;真正的端口发布在容器运行时配置。区分镜像和运行时配置。
为什么容器启动了却仍无法访问?
检查应用绑定地址、实际监听端口和运行时端口映射。正确的 Dockerfile 无法弥补所有运行时不匹配。
使用自己的资料试一试。
将任务提示词中的示例换成你的材料。保留所需条件,再把任务复制到 WebAct。
自定义并复制任务 ↑