Root password inside a Docker container

前端 未结 16 696
没有蜡笔的小新
没有蜡笔的小新 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:09

    When you start the container, you will be root but you won't know what root's pw is. To set it to something you know simply use "passwd root". Snapshot/commit the container to save your actions.

    0 讨论(0)
  • 2020-12-02 04:12

    You can log into the Docker container using the root user (ID = 0) instead of the provided default user when you use the -u option. E.g.

    docker exec -u 0 -it mycontainer bash
    

    root (id = 0) is the default user within a container. The image developer can create additional users. Those users are accessible by name. When passing a numeric ID, the user does not have to exist in the container.

    from Docker documentation

    Update: Of course you can also use the Docker management command for containers to run this:

    docker container exec -u 0 -it mycontainer bash

    0 讨论(0)
  • 2020-12-02 04:16

    try the following command to get the root access

    $ sudo -i 
    
    0 讨论(0)
  • 2020-12-02 04:17

    You can use the USER root command in your Dockerfile.

    0 讨论(0)
提交回复
热议问题