How to pass docker run parameter via kubernetes pod
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Docker docker run parameters map to specific fields in a Kubernetes Pod spec. Environment variables use env, port mappings use containerPort (with a Service for external exposure), volume mounts use volumes + volumeMounts, the entrypoint maps to command, and CMD maps to args. There is no direct equivalent of --privileged or --network host at the docker run level — these require securityContext and hostNetwork fields in the Pod spec.
Docker vs Kubernetes Mapping
| Docker Run | Kubernetes Pod Spec |
docker run image | spec.containers[].image |
-e KEY=VALUE | spec.containers[].env |
-p 8080:80 | spec.containers[].ports + Service |
-v /host:/container | spec.volumes + spec.containers[].volumeMounts |
--name | metadata.name |
--entrypoint | spec.containers[].command |
CMD | spec.containers[].args |
--restart always | spec.restartPolicy |
--memory 512m | spec.containers[].resources.limits.memory |
--cpus 2 | spec.containers[].resources.limits.cpu |
--privileged | spec.containers[].securityContext.privileged |
--network host | spec.hostNetwork: true |
Environment Variables
Command and Arguments
Port Mapping
Volume Mounts
Resource Limits
Security Context
Restart Policy and Health Checks
Common Pitfalls
- Confusing
commandandargs: In Kubernetes,commandoverrides the DockerENTRYPOINTandargsoverridesCMD. Setting onlycommandreplaces the entrypoint but also clears the default CMD. If you just want to pass arguments to the existing entrypoint, useargsonly and omitcommand. - Expecting
-pport mapping to work the same way: Docker's-p 8080:80maps a host port directly. KubernetescontainerPortonly declares which port the container uses — it does not expose it externally. You need aService(NodePort, LoadBalancer, or Ingress) to make the port accessible outside the cluster. - Using
hostPathvolumes in production:hostPathis the Kubernetes equivalent of Docker bind mounts, but it ties the Pod to a specific node. In production, usePersistentVolumeClaimwith a storage class for portability across nodes. - Setting
privileged: truewithout understanding the risk: The--privilegedDocker flag gives the container full access to the host. In Kubernetes,securityContext.privileged: truedoes the same. Usecapabilities.addto grant only the specific capabilities needed instead. - Forgetting that environment variable values must be strings: In Kubernetes YAML, all
envvalues must be strings.value: 5432(without quotes) is parsed as an integer and causes an error. Always quote numeric values:value: "5432".
Summary
- Docker
--entrypointmaps tocommand, DockerCMDmaps toargsin Pod spec - Environment variables use
envwith support for ConfigMaps and Secrets - Port exposure requires both
containerPortin the Pod and aServicefor external access - Volume mounts use
volumes+volumeMounts— prefer PersistentVolumeClaims over hostPath - Resource limits (
--memory,--cpus) map toresources.requestsandresources.limits
Related reading
- how to pass environment variable in kubectl deployment?
- How to pass image pull secret while using 'kubectl run' command?
- How to pass JAAS configuration kafka env variables kubernetes
- How to pass JAAS configuration kafka env variables kubernetes
- How to pass environment variable to docker-compose up
- How to perform kaniko Docker build and push in separate GitLab CI stages?
- How to pass sensitive data to helm values file that is committed?
- How to pass the content of a file to Helm values.yaml

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.