Docker Certified Associate Exam Course
Kubernetes
Commands and Arguments in Kubernetes
In this tutorial, you’ll learn how to configure commands and arguments in a Kubernetes Pod. We’ll use a simple ubuntu-sleeper image that demonstrates how ENTRYPOINT and CMD from a Dockerfile map to the command and args fields in a Pod spec.
Table of Contents
- Recap: ubuntu-sleeper Docker Image
- Create a Pod with the Default Command
- Override CMD with
args - Override ENTRYPOINT with
command - Summary & Mapping Table
- References
Recap: ubuntu-sleeper Docker Image
We built a minimal Docker image called ubuntu-sleeper:
FROM ubuntu
ENTRYPOINT ["sleep"]
CMD ["5"]
- Running without extra arguments uses the default sleep duration (5 seconds):
docker run --name ubuntu-sleeper ubuntu-sleeper - Providing an argument overrides
CMD(for example, sleep 10):docker run --name ubuntu-sleeper ubuntu-sleeper 10
In Docker CLI, anything after the image name replaces the CMD instruction.
Create a Pod with the Default Command
Here’s the simplest Pod manifest that runs sleep 5 by default:
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-pod
spec:
containers:
- name: ubuntu-sleeper
image: ubuntu-sleeper
Apply the Pod:
kubectl create -f pod-definition.yml
By default, Kubernetes uses the image’s ENTRYPOINT + CMD (sleep 5), and the container will exit after 5 seconds.
Override CMD with args
To change the sleep duration without touching the entrypoint, specify an args array in your Pod spec:
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-pod
spec:
containers:
- name: ubuntu-sleeper
image: ubuntu-sleeper
args: ["10"]
This runs sleep 10. Update the Pod:
kubectl apply -f pod-definition.yml
Note
The args field in Kubernetes corresponds directly to the Dockerfile CMD. Any elements you list here will override the default CMD values.
Override ENTRYPOINT with command
If you need to override both the entrypoint and its arguments, use the command field for the entrypoint and args for its parameters:
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-pod
spec:
containers:
- name: ubuntu-sleeper
image: ubuntu-sleeper
command: ["sleep2.0"]
args: ["10"]
commandreplaces the DockerfileENTRYPOINT.argsreplaces the DockerfileCMD.
Apply this configuration:
kubectl create -f pod-definition.yml
Warning
If you override the command field, make sure the specified executable exists in the container filesystem. Otherwise, the Pod will fail to start.
Summary & Mapping Table
The table below summarizes how Dockerfile instructions map to Kubernetes Pod spec fields:
| Dockerfile Instruction | Kubernetes Pod Spec Field | Purpose |
|---|---|---|
| ENTRYPOINT | command | Defines the executable to run |
| CMD | args | Provides default parameters/arguments |
Use these fields to precisely control the process invoked inside your containers.
References
Watch Video
Watch video content