https://www.runoob.com/docker/docker-container-usage.html
Windows 11, Install docker Desktop, choose WSL2 not HyperV
docker run -itd -P --name banana ubuntu /bin/bash # -d detached, -P all ports
docker exec -it banana ubuntu /bin/bash # interactive, terminal
apt-get install curl # this may cause Unable to locate package curl
apt-get update # then can install
apt-get install curl
apt-get install ssh
service ssh start
systemctl enable enable ssh
service ssh status
apt-get install net-tools
apt-get install netcat
apt-get install iputils-ping
ping 172.17.0.1 # this is the host
apt-get install telnet
telnet 172.17.0.1 8000
docker ps -a # active
docker stop banana
docker commit banana banana02
docker run -itd -p 5432:5000 --name banana02 banana02 /bin/bash
docker exec -it banana02 /bin/bash
python3 -m http.server 5000
On host, firefox http://127.0.0.1:5432
On banana02, see 172.17.0.1 GET / 200
docker images
1、从已经创建的容器中更新镜像,并且提交这个镜像 (commit)
docker run -itd --name banana02 ubuntu:22.04 /bin/bash
docker exec -it banana02 /bin/bash
apt-get update
apt-get install -y iputils-ping netcat telnet
docker commit -m="John first commit" -a="John Doe author" banana02 ubuntu:v1
docker run -itd -P --name banana03 ubuntu:v1 /bin/bash
docker exec -it banana03 /bin/bash
nc -l 5000
On host, telnet 127.0.0.1 49154
2、使用 Dockerfile 指令来创建一个新的镜像 (Dockerfile)
cat Dockerfile
FROM ubuntu:22.04
MAINTAINER Fisher "fisher@sudops.com"
RUN apt-get -y update
RUN apt-get install -y iputils-ping netcat telnet
EXPOSE 22
EXPOSE 80
EXPOSE 5000
docker build -t ubuntu:v2 .
docker run -itd -p 5000:5000 -P --name banana04 ubuntu:v2 /bin/bash
docker exec -it banana04 /bin/bash
49159:22
5000:5000
49158:80
docker tag ubuntu:v2 ubuntu:v3
End