Root password inside a Docker container

前端 未结 16 741
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 03:24

I\'m using a Docker image which was built using the USER command to use a non-root user called dev. Inside a container, I\'m \"dev\", but I want to edit the

16条回答
  •  佛祖请我去吃肉
    2020-12-02 04:01

    I had exactly this problem of not being able to su to root because I was running in the container as an unprivileged user.

    But I didn't want to rebuild a new image as the previous answers suggest.

    Instead I have found that I could access the container as root using 'nsenter', see: https://github.com/jpetazzo/nsenter

    First determine the PID of your container on the host:

    docker inspect --format {{.State.Pid}} 
    

    Then use nsenter to enter the container as root

    nsenter --target  --mount --uts --ipc --net --pid
    

提交回复
热议问题