Using CMD Instruction for Default Command in Dockerfile
📖 Scenario: You are creating a Docker image for a simple web server application. You want to set a default command that runs the server when the container starts.
🎯 Goal: Build a Dockerfile that sets up a base image and uses the CMD instruction to specify the default command to run the web server.
📋 What You'll Learn
Use the official
python:3.12-slim base imageCreate a
CMD instruction that runs python3 -m http.server 8000 as the default command💡 Why This Matters
🌍 Real World
Setting a default command in a Dockerfile is common when packaging applications so that containers start the app automatically.
💼 Career
Understanding how to use the <code>CMD</code> instruction and run containers is essential for DevOps roles managing containerized applications.
Progress0 / 4 steps