If you had previously installed Docker Desktop on your system, you need to make sure that what you have installed is up to date. The latest Docker Desktop and the accompanying Docker Engine contain many useful tools to help administrating your images and containers.
This material is written on: - Docker Desktop version 4.35.1 (173168) - Docker Engine: 27.3.1 - Docker Compose: v2.29.7-desktop.1
It is possible that by the time that you read this setup, the versions you have will be higher. That would be a good thing!
1
docker version
containers are instantiated from Docker images.images and containers.
1
2
docker image ls
docker container ls
Images and Container tabs, you can also confirm that there is no existing container or image on your Docker environment.
hello world to the screen. echo command.
1
2
3
4
docker run alpine echo hello, world
docker image ls
docker container ls
docker container ls --all
echo hello, world command.
docker run alpine echo hello world docker: invoke the container engine.run: subcommand to run a container.alpine: name of the image based on which a container will be launched.echo hello, world: the command to be executed in the container environment.docker image ls docker container ls docker container ls --all
1
docker run -it ubuntu bash
-it: combination of -i and -t. -i tells Docker to connect to the container’s stdin for interactive mode-t tells Docker that we want a pseudo-terminalfiglet inside the container (# prompt)
1
figlet hello
bash: figlet: command not found figlet program yet.figlet inside the container (# prompt)
1
2
3
apt update -qq
apt install -y -qq figlet
figlet hello
exit to shutdown the container and back to your normal terminal.figlet again.figlet program still there?figlet program is no longer available again.
Ctrl-C to stop after a few time stamps.
1
docker run ubuntu /bin/sh -c "while date; do sleep 1; done"
1
2
docker run -d jpetazzo/clock
docker container ls
docker container ls command and in the GUI’s container tab.
cd16 --tail N to only look at latest N lines of the log.
1
docker logs --tail 5 cd16
docker kill with the container ID or click on the Stop or Trash Can icons on the container’s line inside the GUI’s Container tab.
1
docker run -it --memory 100M ubuntu bash
--memory: limit size of memory in bytes, megabytes (M), …
1
2
3
4
apt update
apt install -y stress
stress --vm 1 --vm-bytes 99M --vm-keep
stress --vm 1 --vm-bytes 101M --vm-keep
docker run starts a container from a given image.
<registry_name>/<image_name>:[version] URL/<image_name>alpine and ubuntu.
1
docker image ls
Image tab of Docker Desktop, on the top portion of the GUI.
1
docker search mysql
1
2
clear
docker run -it ubuntu /bin/sh
figlet, test, then exit the container
1
2
3
4
apt update -qq
apt install -y -qq figlet
figlet hellp
exit
cb2149... docker diff
1
docker diff cb21
cb2149...
1
2
docker commit cb21 linhbngo/ubuntu_figlet:1.0
docker image ls
docker commit ... command created a new image named ubuntu_figlet that is associated with the DockerHub account linhbngo (my DockerHub account). This combination (linhbngo/ubuntu_figlet) is called a repository, and has the tag 1.0.docker image ls command shows this image and other images available locally for Docker.
docker history ... as shown below.
1
docker history 2379
docker login first to sign in to your Docker Hub account.
1
docker push linhbngo/ubuntu_figlet:1.0