How to install new packages in a non root running container?

Viewed 7386

I need to install simple packages such as curl inside a running container but I face this error:

~ $ apk add curl
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

I know how to chnage the user in a Dockerfile but I don't have access to the docker file and I need to do it while I am inside the container or when opening a terminal inside the container. I tried to use --user= but didn't work:

kubectl exec -n kube-system --user="root" -it tiller-deploy-75f6c87b87-xtpxl /bin/ash
error: auth info "root" does not exist

How I can get root access or install curl?

2 Answers

Use kubectl describe pod ... to find the node running your Pod and the container ID (docker://...)

SSH into the node

run docker exec -u root ID -- /bin/bash

Is your user sudoer? Run this command:

sudo apk add curl

And if the above command didn't work, run this command.

docker exec -it CONTAINER_NAME apk add curl
Related