Dockerfile CMD Explained: Build-Time vs Runtime and How CMD Override Works
Dockerfile শেখার সময় FROM , RUN , WORKDIR , এবং COPY নিয়ে কাজ করার পর খুব স্বাভাবিকভাবেই একটি প্রশ্ন আসে: Container start হলে application automatically কীভাবে run করবে? আমরা যদি শুধু এই ধরনের Dockerfile লিখি— FROM ubuntu:24.04 RUN apt update RUN apt install -y golang WORKDIR /app COPY ./server.go ./server.go তাহলে image তৈরি হবে ঠিকই। Go-ও install হবে। server.go -ও image-এর মধ্যে চলে যাবে। কিন্তু…
Dockerfile CMD instruction is crucial in determining the default runtime command for a container. When you build an image using Dockerfile, the CMD instruction is not executed during the build process. Instead, it serves as a default command for the container when it is started. In the given example, the CMD command is [ go, run, server.go ], which means that when the container is launched using `docker run`, the Go server will automatically start running on port 8080.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.