Unable to write file from docker run inside a kubernetes pod
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
docker kubernetes google-kubernetes-engine docker-volume
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
|
show 1 more comment
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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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
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 anemptyDir
to mount/home/dir
. I changed that to an hostPath and it worked! Thanks so much :)
– donkino
Nov 16 '18 at 14:57
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 anemptyDir
to mount/home/dir
. I changed that to an hostPath and it worked! Thanks so much :)
– donkino
Nov 16 '18 at 14:57
add a comment |
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
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 anemptyDir
to mount/home/dir
. I changed that to an hostPath and it worked! Thanks so much :)
– donkino
Nov 16 '18 at 14:57
add a comment |
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
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
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 anemptyDir
to mount/home/dir
. I changed that to an hostPath and it worked! Thanks so much :)
– donkino
Nov 16 '18 at 14:57
add a comment |
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 anemptyDir
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 16 '18 at 3:01
Vikram HosakoteVikram Hosakote
1,083311
1,083311
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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