Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.
A container is software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, secure, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.
1. Run Docker without sudo
When you install Docker, the docker command must be run with the security privileges of root (using sudo) or by a user in the docker group.
List the groups you belong to with id -Gn
or the obsolete groups
command:
sde@ganges:~$ id -Gn sde adm cdrom sudo dip plugdev lpadmin lxd sambashare
As you can see, the user sde is a member of the sudo group but not the docker group.
If we try to run the docker command without using sudo, we get the following error:
sde@ganges:~$ 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.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'.
2. Add a username to the docker group
We use the usermod command to add our username to the docker group.
$ sudo usermod -aG docker ${USER}
To apply the new group membership, log out of the server and back in, or type the following:
$ su - ${USER}
You will be prompted to enter your user’s password to continue.
3. Verify the username is now a member of the docker group
We can verify that the username has been added by entering the id command again:
sde@ganges:~$ id -Gn sde adm cdrom sudo dip plugdev lpadmin lxd sambashare docker
We can now run the docker command without using sudo.
All articles in this series:
Getting Started with Docker | |
---|---|
Installing Docker Engine | Let's start with the basics. We install Docker Engine on Ubuntu |
Run Docker without sudo | Run Docker without the security privileges of root |
Commands | A brief overview of the 40 Docker commands |
Images | A Docker image is a file used to execute code in a Docker container |
Portainer CE | Install this interface to manage different Docker environments |
Dry | Interactive CLI for Docker containers |