Docker study notes (1)-image, container and log


  • Mirror related commands 


 

 


 

 

Find the mirror (take mirror alpine as an example)

# docker search --help帮助命令
docker search alpine  

docker search --help 帮助命令
docker search --limit 10 alpine   #查找10条记录
docker search --filter stars=100 alpine   #查找星标数量大于100
docker search --no-trunc alpine  #显示完整信息

 Pull mirror

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Options:
  -a, --all-tags pull all mirrors in the warehouse
      --disable-content-trust skip mirror verification (default is true)
      --platform string set multi-platform
  -q, --quiet pull quietly

docker pull --help #帮助命令
docker pull alpine #默认拉取最新版本,等同于docker pull alpine:latest
docker pull alpine:3.13 #拉取3.13版本

View local mirror

docker images --help #帮助命令
docker images

Delete mirror

docker rmi --help #帮助命令
docker rmi 7731472c3f2a #根据IMAGE ID删除镜像
docker rmi -f 7731472c3f2a   #强行删除

Run mirror

The container encapsulates a read-write layer on the image

docker run --help        #帮助命令(非常多)
docker run 7731472c3f2a        #根据IMAGE ID运行镜像
docker run 7731472c3f2a ls -l  #根据IMAGE ID运行镜像,且打印列表信息

 

# 以交互方式运行
# 命名为:nginx
# 将容器的80端口映射到宿主机8888端口
docker run -it --name "nginx" -p 8888:80 f6d0b4767a6c


  • Container related commands

Create a new container through the image and start: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

 

docker attach 容器id  #进入某个容器(使用exit退出后容器也跟着停止运行)

docker exec -it 容器id command  #启动一个伪终端以交互式的方式进入某个容器(使用exit退出后容器不会停止运行)

The container is a thin read and write layer encapsulated on the mirror, and its essence is still to operate the mirror.

As you can see from the picture above, the size of the container is only 39B


Other commands:

docker kill 容器id                #粗暴关闭容器
docker restart 容器id             #重启容器
docker rm $(docker ps -a -q)      #删除所有已经停止的容器
docker rmi $(docker images -q)    #删除所有镜像
docker rmi -f $(docker images -q) #强制删除所有镜像

View container logs

docker logs [OPTIONS] CONTAINER
Options:             
  -f    跟随日志打印
  -n    显示行数(默认全部)
     -tail  显示尾部信息
  -t    显示时间
#展示容器ID为e3262b11bc86的日志,滚动打印,显示时间,并动态展示末尾50行的日志信息
docker logs -ft --tail 50 e3262b11bc86

 


The most important command: docker --help  (super important!!!!!!!!!!!!!!!!!!!!!!!!!!!)

Guess you like

Origin blog.csdn.net/single_0910/article/details/113463601