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 Dekstop 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!
Terminal to find the app.
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 exissting container or image on your Docker envrironment.
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.
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
docker build command builds an image from a Dockerfile.
1
2
3
4
cd
mkdir myimage
cd myimage
nano Dockerfile
Ctrl-X (or Control-X for Mac)Save modified buffer Enter.FROM: the base image for the buildRUN: represents one layer of execution.RUN commands must be non-interactive.myimage pwd.
1
2
3
pwd
ls
docker build -t linhbngo/ubuntu_figlet:2.0 .
-t indicates a tag named figlet will be applied to the image.. indicates that the Dockerfile file is in the current directory.
docker image ls and examining the GUI’s Image tab, you will see that there are now two tags for the same repository name. If you run docker push and check your Docker Hub repo, you will see the second tag now stored in the same repository
1
docker push linhbngo/ubuntu_figlet:2.0
ubuntu_figlet image by launching an interactive container using this image, then immediately run figlet hello world.linhbngo with your own DockerHub account
1
2
3
docker run -it linhbngo/ubuntu_figlet:2.0 /bin/bash
figlet hello world
exit
CMD executes a default program or script with a predefined set of parameters. ENTRYPOINT defines a default program or script with a predefined set of parameters, but also allows users to append additional parameters to docker run call.linhbngo/ubuntu_figlet:3.0.
1
2
3
4
cd
cd myimage
docker build -t linhbngo/ubuntu_figlet:3.0 .
docker run -it linhbngo/ubuntu_figlet:3.0
1
docker image ls
docker system df
Dockerfile as follows:linhbngo/ubuntu_figlet:4.0.
1
2
3
docker build -t linhbngo/ubuntu_figlet:4.0 .
docker run linhbngo/ubuntu_figlet:4.0
docker run linhbngo/ubuntu_figlet:4.0 golden rams
docker run, without any input parameters, does not generate any text.docker run takes golden rams and feeds it to the figlet command specified by ENTRYPOINT.
ENTRYPOINT and CMD can be used together.Dockerfile as follows:linhbngo/ubuntu_figlet:5.0.
1
2
3
docker build -t linhbngo/ubuntu_figlet:5.0 .
docker run linhbngo/ubuntu_figlet:5.0
docker run linhbngo/ubuntu_figlet:5.0 golden rams
ENTRYPOINT: /bin/bash does not work as expected. --entrypoint flag.
1
2
3
docker run -it linhbngo/ubuntu_figlet:5.0
docker run -it --entrypoint bash linhbngo/ubuntu_figlet:5.0
exit
COPY src dstRUN statements.myimage directoryhello.c:Dockerfile.hello:
1
2
docker build -t linhbngo/hello:1.0 -f Dockerfile.hello .
docker run linhbngo/hello:1.0
src inside myimage.hello.c into this directory.
1
2
mkdir src
cp hello.c src/
Dockerfile.gcc:
1
2
docker build -t linhbngo/gcc:1.0 -f Dockerfile.gcc .
docker run -it -v ./src:/ext_src linhbngo/gcc:1.0
hello still persists.
bridge: The default network driver.host: Remove network isolation between the container and the Docker host.none: Completely isolate a container from the host and other containers.overlay: Overlay networks connect multiple Docker daemons together.ipvlan: IPvlan networks provide full control over both IPv4 and IPv6 addressing.macvlan: Assign a MAC address to a container.
1
2
docker run -d -P nginx
docker container ls
-P: make this service reachable from other computers (--publish-all)-d : run in background
1
docker inspect --format '' nginx
{"80/tcp":{}}.80. In turn, this port is mapped to the external port 55000, as shown in the screenshot.127.0.0.1:55000 55000.-p flag as follows:
1
2
docker run -d -p 8000:80 nginx
docker run -d -p 8080:80 -p 8888:80 nginx
port-on-host:port-on-container