How to fix docker: Got permission denied issue

前端 未结 19 979
醉话见心
醉话见心 2020-11-28 00:15

I installed Docker in my machine where I have Ubuntu OS. After than I installed docker, when I run

sudo docker run hello-world

All it\'s ok

相关标签:
19条回答
  • 2020-11-28 00:45

    After you installed docker, created 'docker' group and added user to it, edit docker service unit file:

    sudo nano /usr/lib/systemd/system/docker.service
    

    Add two lines into the section [Service]:

    SupplementaryGroups=docker    
    ExecStartPost=/bin/chmod 666 /var/run/docker.sock
    

    Save the file (Ctrl-X, y, Enter)

    Run and enable the Docker service:

    sudo systemctl daemon-reload
    sudo systemctl start docker
    sudo systemctl enable docker
    
    0 讨论(0)
  • 2020-11-28 00:46

    Seriously guys. Do not add Docker in your groups or modifies the socket posix (without a hardening SELinux), it's a simple way to make a root privesc. Just add an alias in your .bashrc, it's simpler and safer as : alias dc='sudo docker'.

    0 讨论(0)
  • 2020-11-28 00:46

    use this command

    sudo usermod -aG docker $USER
    

    then restart your computer this worked for me.

    0 讨论(0)
  • 2020-11-28 00:49

    I ran into a similar problem as well, but where the container I wanted to create needed to mount /var/run/docker.sock as a volume (Portainer Agent), while running it all under a different namespace. Normally a container does not care about which namespace it is started in -- that is sort of the point -- but since access was made from a different namespace, this had to be circumvented.

    Adding --userns=host to the run command for the container enabled it to use the attain the correct permissions.

    Quite a specific use case, but after more research hours than I want to admit I just thought I should share it with the world if someone else ends up in this situation :)

    0 讨论(0)
  • 2020-11-28 00:55

    If you want to run docker as non-root user then you need to add it to the docker group.

    1. Create the docker group if it does not exist
    $ sudo groupadd docker
    
    1. Add your user to the docker group.
    $ sudo usermod -aG docker $USER
    
    1. Run the following command or Logout and login again and run (that doesn't work you may need to reboot your machine first)
    $ newgrp docker
    
    
    1. Check if docker can be run without root
    $ docker run hello-world
    

    Reboot if still got error

    $ reboot
    

    Taken from the docker official documentation: manage-docker-as-a-non-root-user

    0 讨论(0)
  • 2020-11-28 00:57
    1. Add current user to docker group
    sudo usermod -aG docker $USER
    
    1. Change the permissions of docker socket to be able to connect to the docker daemon /var/run/docker.sock
    sudo chmod 666 /var/run/docker.sock
    
    0 讨论(0)
提交回复
热议问题