Unit 1 Chapter 4: Linux Docker Images
In this chapter, you will try out various Linux distros through Docker images.
Topics Covered
- Basic Docker commands
List of Docker Containers and Images
- At the end of the previous chapter, you deleted all containers and images.
- Enter the command
docker ps -a
to show all of the Docker containers currently in your system. Of course, there will be none, and the screen output will be the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- Enter the command
docker images -a
to show all of the Docker images currently in your system. Again, there will be none, and the screen output will be the following:
REPOSITORY TAG IMAGE ID CREATED SIZE
Debian Linux Image
- Enter the command
docker run debian
. - The screen output should look something like this:
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
e9afc4f90ab0: Pull complete
Digest: sha256:46d659005ca1151087efa997f1039ae45a7bf7a2cbbe2d17d3dcbda632a3ee9a
Status: Downloaded newer image for debian:latest
- Enter the command
docker run -it debian bash
. This starts up a Bash shell within the Debian Linux Docker container. - Enter the command
whoami
. The output will show that you're the root user. Please note that most Docker images have only a root user and no regular user. - Enter the command
cat /etc/os-release
. The output will show that you're in Debian Linux. - Enter the command
apt-get update
. This updates the software package list within your Docker container's Debian environment. - Enter the command
apt-get upgrade -y
. This updates all the software within your Docker container's Debian environment. - Enter the command
exit
to return to your host system.
Ubuntu Linux Docker Image
- Enter the command
docker run ubuntu
. - The screen output should look something like this:
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
Digest: sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
Status: Downloaded newer image for ubuntu:latest
- Enter the command
docker run -it ubuntu bash
. This starts up a Bash shell within the Ubuntu Linux Docker container. - Enter the command
whoami
. The output will show that you're the root user. - Enter the command
cat /etc/os-release
. The output will show that you're in Ubuntu Linux. - Enter the command
apt-get update
. This updates the software package list within your Docker container's Ubuntu environment. - Enter the command
apt-get upgrade -y
. This updates all the software within your Docker container's Ubuntu environment. - Enter the command
exit
to return to your host system.
Alpine Linux Docker Image
- Enter the command
docker run alpine
. - The screen output should look something like this:
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
df20fa9351a1: Pull complete
Digest: sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321
Status: Downloaded newer image for alpine:latest
- Enter the command
docker run -it alpine sh
. This starts up a shell within the Alpine Linux Docker container. - Enter the command
whoami
. The output will show that you're the root user. - Enter the command
cat /etc/os-release
. The output will show that you're in Alpine Linux. - Enter the command
apk update
. This updates the software package list within your Docker container's Alpine environment. - Enter the command
apk upgrade
. This updates all the software within your Docker container's Alpine environment. - Enter the command
exit
to return to your host system.
ArchLinux Docker Image
- Enter the command
docker run archlinux
. - The screen output should look something like this:
Unable to find image 'archlinux:latest' locally
latest: Pulling from library/archlinux
238e7cef5675: Pull complete
231c6d24d179: Pull complete
1c2b33cecfa4: Pull complete
9e0e057fb0da: Pull complete
3b9ccf3aa70b: Pull complete
508465e7010b: Pull complete
Digest: sha256:a5bbbcdbb9bbef3b5db3ec97c7bf659162904576bdd2dd7165ffc4fbe812088e
Status: Downloaded newer image for archlinux:latest
- Enter the command
docker run -it archlinux bash
. This starts up a shell within the Arch Linux Docker container. - Enter the command
whoami
. The output will show that you're the root user. - Enter the command
cat /etc/os-release
. The output will show that you're in Arch Linux. - Enter the command
pacman -Sy
. This updates the software package list within your Docker container's Arch Linux environment. - Enter the command
pacman -Syu
. When prompted, enter "y" to proceed with upgrading all the software within your Docker container's Arch Linux environment. - Enter the command
exit
to return to your host system.
Cleaning Up
- To delete all Docker networks, enter the command
docker network prune -f
. - To view the list of Docker containers, enter the command
docker ps -a
. - To delete all of these Docker containers, enter the following commands:
for i in $(docker ps -a -q)
do
docker kill $i; wait;
docker rm -f $i; wait;
done;
- To view the list of Docker containers, enter the command
docker ps -a
. This list should now be empty. - To view the list of Docker images, enter the command
docker images -a
. - To delete all of these Docker images, enter the following commands:
for i in $(docker images -a -q)
do
docker kill $i; wait;
docker rmi -f $i; wait;
done;