Answers: <blockquote>
  <p>Now I wish to create an image out of that container to record all those changes in a single image.</p>
  </blockquote>
  <p>That is generally the wrong way to go about it: you should create your image using a <code>Dockerfile</code>, and then deploy it to Kubernetes to test it. You should treat your running container as &quot;read-only&quot; and only makes changes by updating your Dockerfile (or similar) and re-building the image.</p>
  <p>Doing things this way ensures that you are able to re-create the image, and allows you to use version control on the Dockerfile so that you have a record of what changes you made and why.</p>
  <blockquote>
  <p>Is there a way to something similar but considering the container is managed inside a pod of k8s?</p>
  </blockquote>
  <p>The only way to create an image* from the running container would be to use <code>docker commit</code>. There is no Kubernetes mechanism for performing this action. You'll need to log into the Kubernetes node on which your container is running and run <code>docker commit</code> there, and then potentially <code>docker push</code> the image to a repository if you intend on running it elsewhere.</p>
  <hr />
  <p>*: That's a bit of a simplification. E.g., you could use something like <code>tar</code> to export the filesystem, and once you have that there are various way to unpack it into an image.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-10T17:08:10.933Z
Answers: Yeah I know dockerfile would be better, but I was just looking for a quick workarround to get all that I have done without having to do Dockerfile for saving time. It's not something that will be changing in the future, it was just a one-time thing. Either way, when you mention to run docker commit on the kubernetes node, to what would I commit to? the pod is not a container that I could commit right?
Answers: Eugenio.Gastelum96
Answers: CC BY-SA 4.0
Answers: 2023-04-10T17:54:05.397Z
Answers: You said in your question that you're using the docker driver for Kubernetes. That means that each container in your pod is an actual Docker container. I don't use Docker in my k8s environments, but you should be able to run `docker ps` on the appropriate node and get a list of containers; from there you'll probably need to match up the container id with the pod somehow.
Answers: larsks
Answers: CC BY-SA 4.0
Answers: 2023-04-13T19:16:15.170Z
Answers: well I have made a deployment of 3 pods, each with 2 containers. I wen I run docker ps on the managing noe (I am using minikube so it's all on my local pc really) I get only 1 kubernetes container. And even if I delete the deployment and have no deployments & pods , that container is still there. Should I have seen 1 k8s container per pod-container there was?
Answers: Eugenio.Gastelum96
Answers: CC BY-SA 4.0
Answers: 2023-04-10T15:35:15.237Z
Answers: 2023-04-10T15:35:15.237Z
Answers: larsks
Body: <p>I have made a pod, and it has only one container, I've been able to connect ot it by using <code>kubectl exec -it -c &lt;container_name&gt; &lt;pod_name&gt; bash</code></p>
  <p>And I've installed and done several stuff on it.</p>
  <p>Now I wish to create an image out of that container to record all those changes in a single image.</p>
  <p>I am using docker as the driver. And typically, if this container would have been just any other regular docker container (not managed by k8s), I would have just made a <code>docker commit &lt;container_name&gt;</code></p>
  <p>Is there a way to something similar but considering the container is managed inside a pod of k8s?</p>
  
Tags: <docker><kubernetes><containers><images>
Title: How can I make an image out of a k8s specific pod container
UserDisplayName: Eugenio.Gastelum96
ThreadText: # How can I make an image out of a k8s specific pod container
  
  (Asked by: username_0 on 2023-04-09)
  
  I have made a pod, and it has only one container, I've been able to connect ot it by using `kubectl exec -it -c <container_name> <pod_name> bash`
  
  And I've installed and done several stuff on it.
  
  Now I wish to create an image out of that container to record all those changes in a single image.
  
  I am using docker as the driver. And typically, if this container would have been just any other regular docker container (not managed by k8s), I would have just made a `docker commit <container_name>`
  
  Is there a way to something similar but considering the container is managed inside a pod of k8s?
  
  **Tags:** docker, kubernetes, containers, images
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-04-10. Score: 0
  
  > Now I wish to create an image out of that container to record all those changes in a single image.
  
  That is generally the wrong way to go about it: you should create your image using a `Dockerfile`, and then deploy it to Kubernetes to test it. You should treat your running container as "read-only" and only makes changes by updating your Dockerfile (or similar) and re-building the image.
  
  Doing things this way ensures that you are able to re-create the image, and allows you to use version control on the Dockerfile so that you have a record of what changes you made and why.
  
  > Is there a way to something similar but considering the container is managed inside a pod of k8s?
  
  The only way to create an image\* from the running container would be to use `docker commit`. There is no Kubernetes mechanism for performing this action. You'll need to log into the Kubernetes node on which your container is running and run `docker commit` there, and then potentially `docker push` the image to a repository if you intend on running it elsewhere.
  
  ---
  
  \*: That's a bit of a simplification. E.g., you could use something like `tar` to export the filesystem, and once you have that there are various way to unpack it into an image.
  
  > **Comments:**
  > **username_0**: Yeah I know dockerfile would be better, but I was just looking for a quick workarround to get all that I have done without having to do Dockerfile for saving time. It's not something that will be changing in the future, it was just a one-time thing. Either way, when you mention to run docker commit on the kubernetes node, to what would I commit to? the pod is not a container that I could commit right?  
  > **username_1**: You said in your question that you're using the docker driver for Kubernetes. That means that each container in your pod is an actual Docker container. I don't use Docker in my k8s environments, but you should be able to run `docker ps` on the appropriate node and get a list of containers; from there you'll probably need to match up the container id with the pod somehow.  
  > **username_0**: well I have made a deployment of 3 pods, each with 2 containers. I wen I run docker ps on the managing noe (I am using minikube so it's all on my local pc really) I get only 1 kubernetes container. And even if I delete the deployment and have no deployments & pods , that container is still there. Should I have seen 1 k8s container per pod-container there was?  
  
  ---
  
  