Začínáme s Dockerem – Přidání uživatele do skupiny docker

Docker můžeme po instalaci spouštět pouze jako root uživatel (sudo). Pokud chcete docker spouštět pod svým uživatelem, je třeba přidat uživatele do skupiny docker.

vitfo@vitfo-VirtualBox:~$ sudo groupadd docker
groupadd: group 'docker' already exists

Je vidět, že docker už skupinu vytvořil.

vitfo@vitfo-VirtualBox:~$ sudo usermod -aG docker $USER

Přesvědčíme se, že uživatel je přidán do skupiny

vitfo@vitfo-VirtualBox:/etc$ cat /etc/group | grep docker
docker:x:998:vitfo

Nyní zkusíme vytvořit kontejner z image hello-world bez zadání sudo.

vitfo@vitfo-VirtualBox:~$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

Dostáváme chybu, že nemáme oprávnění. Nepomohlo ani vypnutí a zapnutí terminálu. Vyřešil to až restart počítače.

vitfo@vitfo-VirtualBox:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Pokud jste si docker zkoušeli se sudo, může se vám stát, že budete dostávat chyby. Je nutné změnit vlastnictví souborů a adresářů, které docker používá.

Zdroj: docs.docker.com/…/linux-postinstall/

Napsat komentář