Search code examples
dockerkuberneteskubernetes-poddocker-run

Docker run command options in kubernetes


I am starting my docker container using following command
docker run -it -d -p 80001:8000.
Now i want to use use docker container in kubernetes using deployment. How to setup container spec secion of deployment for above mentioned arugment -it and -d. both are require.So first allocate stdin and tty to pod and then keep it running into detach mode.


Solution

  • You don't need to add -it -d. Kubernetes deployment will wake-up the pod in detached mode. Interactive mode (-i) has no sense because it runs in detached mode, and -t (allowcate pseudo tty) also don't needed. There is thread in about dealing with tty in deployments here https://www.reddit.com/r/kubernetes/comments/hczzi2/when_dealing_with_deployments_what_does_tty_true/

    If you need later access to this pod you can use kubectl exec -ti <podname> -- bash.

    Remember that your pod should run in background some kind of service or at least an sleep loop.

    Here more information on how to do this kind of loop How can I keep a container running on Kubernetes?

    Update:

    If you want to run a pod in Kubernetes with -ti you can do:

    kubectl run -i -t busybox --image=busybox --restart=Never --port=8001

    after exit remember to delete it with kubectl delete pod busybox

    If you want forward ports you can do:

    kubectl port-forward busybox 8001:8001 and go to localhost:8001