I have listed all the necessary commands of Docker below. In case if any is missing or if any improvement required, please share in comments so I can update accordingly. Thanks and enjoy tutorial.
1) docker –verison
display version command
2) docker version
3) docker image ls
Display images which are downloaded or created.
4) docker image pull ubuntu:latest
Above command pull image from docker hub.
5) docker container run -it ubuntu:latest /bin/bash
Above command launch and start image in container which is fetched in docker host from above command.
6) ps -elf (inside bash command)
7) Ctrl + PQ (Command exit from bash but keep it running)
8) docker container ls
Shows above container running. Also container names in last column called "NAMES"
9) docker container exec -ti <container-name>/<container-id> bash
10) docker container <container-name>/<container-id>
>>>>>>>>>>>DOCKER DEVELOPER <<<<<<<<<<<<<<<<<<<<<<<<<<<
11) Create folder and run command
git clone https://github.com/nigelpoulton/psweb.git
12) Goto into new folder created and run following command.
docker image build -t test:latest .
13) docker image ls
14) docker container run -d --name web1 -p 8080:8080 test:latest
15) docker container ls
16) docker container run --name zm -it ubuntu:latest sh
command generates id
17) docker rm <dockerid_generated_after_executing_command15>
18) Docker images can be found inside
/var/lib/docker/ on linux
and on windows inside c:\program data\docker\windowsfilter
19) docker image inspect ubuntu:latest
20) docker image ls --digests alpine
21) docker image rm alpine:latest
Above command Remove mentioned image e.g., remove alpine:latest
22) docker image pull alpine@sha26:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Above command pull image of alpine using digest. Digest is a hashcode which is created from the contents of file itself. Advantage of it over Tag is that it will never be the same. Tag can be mistakenly same. For example you download image with the tag "latest" and also push/update them image on server (e.g., DockerHub) with same Tag mistakenly. This will not be possible with Digest as it uses file contents/image contents to create Hash and image will always be change if you made any change in it. Even a single word written in image will change Digest/hash code of image.
23) docker image ls -q
List all images IDs
24) docker image rm $(docker image ls -q) -f
OR
docker container rm $(docker container ls -aq) -f
1st command remove all images from Docker/your system. Second command will remove all containers from your system. The -f flag
forces the operation so that running containers will also be destroyed.
25) docker container run -it alpine:latest sleep 10
Hold above container for 10 seconds and then sleep/exit from process.
26) usermod -aG docker <user>
Above command will add any user you mentioned to docker group.
27) service docker status
and systemctl is-active docker
Above both commands check status of docker. 1st command will show some more details where as second command will only show its status.
28) docker container run --name myubuntu -it ubuntu:latest /bin/bash
Above command will start your container. Exit from shell of container using Ctrl+PQ without terminating the process. Please note that containter will be Alive till any of the process is running inside it. Once no process is alive, container will be terminated itself.
To reconnect with the same process, you need to know container image id. Type following command.
docker container ls -q
This command will provide your 12 characters of container image id (e.g., 36aa4eb7a789).
To reconnect to the image, use below command.
docker container exec -it 36aa4eb7a789 bash
29) docker container run -d --name webserver -p 80:8080 \
nigelpoulton/pluralsight-docker-ci
Above command will download image of pluralSight from nigelpoulton dockerHUB Account nigelpoulton/pluralsight-docker-ci. It will also
detach process and start web server on 8080 port.
"d" stands for daemon mode.
-it and -d are mutually exlcusive modes/commands and can not be used together for starting a container.
30) docker image history web:latest
Display commands history executed on particular image.