Home > Mobile >  Why cant create file inside nginx container?
Why cant create file inside nginx container?

Time:10-04

What i want do is create container and create file inside the container. so thought first try would be to list files so i ran. kubectl run test-nginx --restart=Never --image nginx:alpine -- /bin/sh -c "ls". It works as expected. Next would be kubectl run test-nginx --restart=Never --image nginx:alpine -- /bin/sh -c "touch index.txt". But it fails saying Error. why it cant just create file inside the container. Am i missing something ?

CodePudding user response:

Please post the full error message that you are facing.

If it is a permission issue, You can try running it in privileged mode:

kubectl run test-nginx --restart=Never --privileged=true --image nginx:alpine -- /bin/bash -c "touch index.txt"

CodePudding user response:

Use /bin/sh not /bin/bash

As of this writing, the nginx:alpine image from dockerhub doesn't have /bin/bash.

I'm not sure why kubectl run test-nginx --restart=Never --image nginx:alpine -- /bin/bash -c "ls" works for you, unless the image is a custom one..

  • Related