Installing Docker
- Log into shell and use apt to update the package repositories.
sudo apt update
- Use apt to install Docker.
sudo apt install docker
- Have Docker engine start after a power cycle / reboot
sudo systemctl enable docker
Note: Docker CE (Community Edition) with CLI (Command Line Interface) and required support packages will be installed.
Running Docker without sudo
Docker requires elevated privileges, so every Docker command must be prefaced with sudo.
You can run without this requirement by adding your shell username to the Docker user group.
sudo usermod -aG docker YourShellUsername
At this point, you must log out of any/all shell sessions you have open and log back in.
To prove the user can run Docker without sudo, a simple test:
docker run hello-world
Restart the container on boot/power cycle
Note that the provided examples have some variation of the --restart
option. If you want your container to start when the groov device starts up, you MUST include this option and the correct command for that container. Exactly which restart command parameters varies depending on how you want the container to behave. For more on the restart options see the Docker restart documentation.
Container names
If you do not include the command line switch --name
containername then Docker will give it a random name, something like ‘dancing-ibis’, thus every container will have a unique name.
Commands for monitoring and managing containers:
List running containers:
sudo docker ps
Restart a container:
sudo docker restart containername
Stop a container:
sudo docker stop containername
Stop a container after 30 seconds’ grace: (i.e., send SIGTERM after 30 seconds)
sudo docker stop –time=30 containername
Hard stop a container:
sudo docker kill containername
Pause a container:
sudo docker pause containername
sudo docker unpause containername
Remove a container:
sudo docker rm containername
Remove the container and its data volume:
sudo docker rm -v containername
(removes config files used on the host. Danger!)
Delete all unused containers:
sudo docker system prune
sudo docker system prune --all
(Leave config files in the volume on the host)
sudo docker system prune --all --volumes
(remove config files off the host. Danger!).
View container logs:
sudo docker logs containername
View a running log
sudo docker logs -f containername