
Docker Tutorial
Table of Contents
Learning About Docker
Playlist by Learn Linux TV
What is Docker:
Installing Docker: GNU/Linux:
1. Install
$ sudo apt update && sudo apt upgrade
$ sudo apt install docker.io
2. System Check
$ systemctl status docker
Output
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-09-01 07:13:06 IST; 2min 26s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2468 (dockerd)
If it says disabled in Loaded section
$ systemctl enable docker
This will enable docker to run on startup.
3. Docker Check
$ sudo docker run hello-world
- Permission Issues
Run
$ docker images
If you are getting Permission Denied error
$ sudo usermod -aG docker yourusername && reboot
Rebooting because logging out and in did not help.
Now run
$ docker images
Image is the blueprint for container.
Docker Commands:
For searching images:
$ docker search image-name
Downloading Images:
$ docker pull image-name
Running a container - 1:
$ docker run image-name
If the image has nothing to do, docker will stop it.
List of running Containers
$ docker ps
For all
$ docker ps -a
Running a container - 2:
$ docker run -it ubuntu /bin/bash
-t : Allocate a pseudo-tty
-i : Keep STDIN open even if not attached
-d : Detached, for running container in background
-p : Ports (host:container)
This will run the Ubuntu container and open bash shell into the container. You may use it normally and install applications. But after you have logged out of the container all the data will be gone. This is sort of a temporary container.
Container by default don’t save changes.
Attach detached container:
$ docker attach container-name/id
Keep the container state:
Inside the container press
CTRL + p + q
This will exit from container but the container will run in background.
Docker Image Creation:
$ docker commit container-id new-container-name:tag-name