Unable to write file from docker run inside a kubernetes pod












1















I have a docker image that uses a volume to write files:



docker run --rm -v /home/dir:/out/ image:cli args


when I try to run this inside a pod the container exit normally but no file is written.



I don't get it.



The container throw errors if it does not find the volume, for example if I run it without the -v option it throws:



Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/out/file.txt'.


But I don't have any error from the container.
It finishes like it wrote files, but files do not exist.



I'm quite new to Kubernetes but this is getting me crazy.



Does kubernetes prevent files from being written? or am I missing something obvious?



The whole Kubernetes context is managed by GCP composer-airflow, if it helps...



docker -v: Docker version 17.03.2-ce, build f5ec1e2









share|improve this question

























  • hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

    – Narendra
    Nov 15 '18 at 22:20











  • Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

    – donkino
    Nov 15 '18 at 22:25











  • so is your pod (outer docker) always running. or it exits as well.

    – Narendra
    Nov 15 '18 at 22:28











  • Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

    – David Maze
    Nov 15 '18 at 22:54











  • Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

    – donkino
    Nov 15 '18 at 23:33
















1















I have a docker image that uses a volume to write files:



docker run --rm -v /home/dir:/out/ image:cli args


when I try to run this inside a pod the container exit normally but no file is written.



I don't get it.



The container throw errors if it does not find the volume, for example if I run it without the -v option it throws:



Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/out/file.txt'.


But I don't have any error from the container.
It finishes like it wrote files, but files do not exist.



I'm quite new to Kubernetes but this is getting me crazy.



Does kubernetes prevent files from being written? or am I missing something obvious?



The whole Kubernetes context is managed by GCP composer-airflow, if it helps...



docker -v: Docker version 17.03.2-ce, build f5ec1e2









share|improve this question

























  • hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

    – Narendra
    Nov 15 '18 at 22:20











  • Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

    – donkino
    Nov 15 '18 at 22:25











  • so is your pod (outer docker) always running. or it exits as well.

    – Narendra
    Nov 15 '18 at 22:28











  • Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

    – David Maze
    Nov 15 '18 at 22:54











  • Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

    – donkino
    Nov 15 '18 at 23:33














1












1








1








I have a docker image that uses a volume to write files:



docker run --rm -v /home/dir:/out/ image:cli args


when I try to run this inside a pod the container exit normally but no file is written.



I don't get it.



The container throw errors if it does not find the volume, for example if I run it without the -v option it throws:



Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/out/file.txt'.


But I don't have any error from the container.
It finishes like it wrote files, but files do not exist.



I'm quite new to Kubernetes but this is getting me crazy.



Does kubernetes prevent files from being written? or am I missing something obvious?



The whole Kubernetes context is managed by GCP composer-airflow, if it helps...



docker -v: Docker version 17.03.2-ce, build f5ec1e2









share|improve this question
















I have a docker image that uses a volume to write files:



docker run --rm -v /home/dir:/out/ image:cli args


when I try to run this inside a pod the container exit normally but no file is written.



I don't get it.



The container throw errors if it does not find the volume, for example if I run it without the -v option it throws:



Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/out/file.txt'.


But I don't have any error from the container.
It finishes like it wrote files, but files do not exist.



I'm quite new to Kubernetes but this is getting me crazy.



Does kubernetes prevent files from being written? or am I missing something obvious?



The whole Kubernetes context is managed by GCP composer-airflow, if it helps...



docker -v: Docker version 17.03.2-ce, build f5ec1e2






docker kubernetes google-kubernetes-engine docker-volume






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 22:34









Rico

27.5k94865




27.5k94865










asked Nov 15 '18 at 22:12









donkinodonkino

557




557













  • hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

    – Narendra
    Nov 15 '18 at 22:20











  • Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

    – donkino
    Nov 15 '18 at 22:25











  • so is your pod (outer docker) always running. or it exits as well.

    – Narendra
    Nov 15 '18 at 22:28











  • Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

    – David Maze
    Nov 15 '18 at 22:54











  • Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

    – donkino
    Nov 15 '18 at 23:33



















  • hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

    – Narendra
    Nov 15 '18 at 22:20











  • Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

    – donkino
    Nov 15 '18 at 22:25











  • so is your pod (outer docker) always running. or it exits as well.

    – Narendra
    Nov 15 '18 at 22:28











  • Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

    – David Maze
    Nov 15 '18 at 22:54











  • Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

    – donkino
    Nov 15 '18 at 23:33

















hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

– Narendra
Nov 15 '18 at 22:20





hey! so you are running a docker container within a container because pod itself is a container. One thing to make sure he is that, where is the "/home/dir" is it outside your pod or otherwise. then only it can be mounted.

– Narendra
Nov 15 '18 at 22:20













Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

– donkino
Nov 15 '18 at 22:25





Yeah, that's docker in docker. The /home/dir is inside the pod. Here the pod is the container host right?

– donkino
Nov 15 '18 at 22:25













so is your pod (outer docker) always running. or it exits as well.

– Narendra
Nov 15 '18 at 22:28





so is your pod (outer docker) always running. or it exits as well.

– Narendra
Nov 15 '18 at 22:28













Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

– David Maze
Nov 15 '18 at 22:54





Standard Kubernetes does not run Docker-in-Docker (that's generally discouraged); and the Pod is a separate layer from either the host or the container proper. You need to create a volume in the Pod and mount it in the container. This workload doesn't seem like a great match for Kubernetes as you've described it, though.

– David Maze
Nov 15 '18 at 22:54













Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

– donkino
Nov 15 '18 at 23:33





Thx @DavidMaze . About kubernetes I does not have much of choice, this problem is part of a workflow inside composer-airflow, which run in kubernetes. And our workflow consist in a serie of commands run on different docker containers, each using files generated by the precedent. So I'll give a try to the volume in the pod mounted in the container. Still Idon't get why once inside the pod (and staying in the pod) the files are not created without the container crashing.. (i'll paste an example, it starts to be a lot of containers haha)

– donkino
Nov 15 '18 at 23:33












2 Answers
2






active

oldest

votes


















1














If you want to have that behavior in Kubernetes you can use a hostPath volume.



Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.



apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: image:cli
name: test-container
volumeMounts:
- mountPath: /home/dir
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /out
type: Directory





share|improve this answer
























  • Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

    – donkino
    Nov 15 '18 at 22:51











  • You may not be able to write to /out

    – Rico
    Nov 15 '18 at 22:54











  • Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

    – donkino
    Nov 16 '18 at 14:57





















1















when I try to run this inside a pod the container exit normally but no file is written




First of all, there is no need to run the docker run command inside the pod :). A spec file (yaml) should be written for the pod and kubernetes will run the container in the pod using docker for you. Ideally, you don't need to run docker commands when using kubernetes (unless you are debugging docker-related issues).



This link has useful kubectl commands for docker users.



If you are used to docker-compose, refer Kompose to go from docker-compose to kubernetes:




  • https://github.com/kubernetes/kompose

  • http://kompose.io


Some options to mount a directory on the host as a volume inside the container in kubernetes:




  • hostPath

  • emptyDir

  • configMap






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328627%2funable-to-write-file-from-docker-run-inside-a-kubernetes-pod%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If you want to have that behavior in Kubernetes you can use a hostPath volume.



    Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.



    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pd
    spec:
    containers:
    - image: image:cli
    name: test-container
    volumeMounts:
    - mountPath: /home/dir
    name: test-volume
    volumes:
    - name: test-volume
    hostPath:
    path: /out
    type: Directory





    share|improve this answer
























    • Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

      – donkino
      Nov 15 '18 at 22:51











    • You may not be able to write to /out

      – Rico
      Nov 15 '18 at 22:54











    • Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

      – donkino
      Nov 16 '18 at 14:57


















    1














    If you want to have that behavior in Kubernetes you can use a hostPath volume.



    Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.



    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pd
    spec:
    containers:
    - image: image:cli
    name: test-container
    volumeMounts:
    - mountPath: /home/dir
    name: test-volume
    volumes:
    - name: test-volume
    hostPath:
    path: /out
    type: Directory





    share|improve this answer
























    • Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

      – donkino
      Nov 15 '18 at 22:51











    • You may not be able to write to /out

      – Rico
      Nov 15 '18 at 22:54











    • Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

      – donkino
      Nov 16 '18 at 14:57
















    1












    1








    1







    If you want to have that behavior in Kubernetes you can use a hostPath volume.



    Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.



    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pd
    spec:
    containers:
    - image: image:cli
    name: test-container
    volumeMounts:
    - mountPath: /home/dir
    name: test-volume
    volumes:
    - name: test-volume
    hostPath:
    path: /out
    type: Directory





    share|improve this answer













    If you want to have that behavior in Kubernetes you can use a hostPath volume.



    Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.



    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pd
    spec:
    containers:
    - image: image:cli
    name: test-container
    volumeMounts:
    - mountPath: /home/dir
    name: test-volume
    volumes:
    - name: test-volume
    hostPath:
    path: /out
    type: Directory






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 15 '18 at 22:38









    RicoRico

    27.5k94865




    27.5k94865













    • Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

      – donkino
      Nov 15 '18 at 22:51











    • You may not be able to write to /out

      – Rico
      Nov 15 '18 at 22:54











    • Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

      – donkino
      Nov 16 '18 at 14:57





















    • Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

      – donkino
      Nov 15 '18 at 22:51











    • You may not be able to write to /out

      – Rico
      Nov 15 '18 at 22:54











    • Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

      – donkino
      Nov 16 '18 at 14:57



















    Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

    – donkino
    Nov 15 '18 at 22:51





    Thx, I'll try that. But problem is the file doesn't exist while the pod is alive. I mean I enter the pod (via kubectl exec - it pod - - bin/bash), run the container, and no files...

    – donkino
    Nov 15 '18 at 22:51













    You may not be able to write to /out

    – Rico
    Nov 15 '18 at 22:54





    You may not be able to write to /out

    – Rico
    Nov 15 '18 at 22:54













    Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

    – donkino
    Nov 16 '18 at 14:57







    Hey! I was using an emptyDir to mount /home/dir. I changed that to an hostPath and it worked! Thanks so much :)

    – donkino
    Nov 16 '18 at 14:57















    1















    when I try to run this inside a pod the container exit normally but no file is written




    First of all, there is no need to run the docker run command inside the pod :). A spec file (yaml) should be written for the pod and kubernetes will run the container in the pod using docker for you. Ideally, you don't need to run docker commands when using kubernetes (unless you are debugging docker-related issues).



    This link has useful kubectl commands for docker users.



    If you are used to docker-compose, refer Kompose to go from docker-compose to kubernetes:




    • https://github.com/kubernetes/kompose

    • http://kompose.io


    Some options to mount a directory on the host as a volume inside the container in kubernetes:




    • hostPath

    • emptyDir

    • configMap






    share|improve this answer




























      1















      when I try to run this inside a pod the container exit normally but no file is written




      First of all, there is no need to run the docker run command inside the pod :). A spec file (yaml) should be written for the pod and kubernetes will run the container in the pod using docker for you. Ideally, you don't need to run docker commands when using kubernetes (unless you are debugging docker-related issues).



      This link has useful kubectl commands for docker users.



      If you are used to docker-compose, refer Kompose to go from docker-compose to kubernetes:




      • https://github.com/kubernetes/kompose

      • http://kompose.io


      Some options to mount a directory on the host as a volume inside the container in kubernetes:




      • hostPath

      • emptyDir

      • configMap






      share|improve this answer


























        1












        1








        1








        when I try to run this inside a pod the container exit normally but no file is written




        First of all, there is no need to run the docker run command inside the pod :). A spec file (yaml) should be written for the pod and kubernetes will run the container in the pod using docker for you. Ideally, you don't need to run docker commands when using kubernetes (unless you are debugging docker-related issues).



        This link has useful kubectl commands for docker users.



        If you are used to docker-compose, refer Kompose to go from docker-compose to kubernetes:




        • https://github.com/kubernetes/kompose

        • http://kompose.io


        Some options to mount a directory on the host as a volume inside the container in kubernetes:




        • hostPath

        • emptyDir

        • configMap






        share|improve this answer














        when I try to run this inside a pod the container exit normally but no file is written




        First of all, there is no need to run the docker run command inside the pod :). A spec file (yaml) should be written for the pod and kubernetes will run the container in the pod using docker for you. Ideally, you don't need to run docker commands when using kubernetes (unless you are debugging docker-related issues).



        This link has useful kubectl commands for docker users.



        If you are used to docker-compose, refer Kompose to go from docker-compose to kubernetes:




        • https://github.com/kubernetes/kompose

        • http://kompose.io


        Some options to mount a directory on the host as a volume inside the container in kubernetes:




        • hostPath

        • emptyDir

        • configMap







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 3:01









        Vikram HosakoteVikram Hosakote

        1,083311




        1,083311






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328627%2funable-to-write-file-from-docker-run-inside-a-kubernetes-pod%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()