公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

说明:把Docker常用命令归纳到linux基础,是因为我本地docker安装在centos上,平时运行实验镜像的时候都是直接在centos上操作运行。

1、docker版本、状态查看

[root@k8smaster test]# docker -v
Docker version 20.10.6, build 370c289
[root@k8smaster test]# docker version
Client: Docker Engine - Community
 Version:           20.10.6
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        370c289
 Built:             Fri Apr  9 22:45:33 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
......
......

2、镜像(image)操作

从仓库拉取镜像:

//  Docker的镜像存储在镜像注册中心(image registry)中,默认是Docker Hub(https://hub.docker.com/),在拉取镜像的时候也可以指定其它注册中心。
//  拉取镜像,使用docker image pull命令
[root@k8smaster test]# docker image pull --help

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

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is
                                multi-platform capable
  -q, --quiet                   Suppress verbose output

查询已有镜像:

[root@k8smaster test]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 months ago   13.3kB

删除镜像:

[root@k8smaster test]# docker rmi --help

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents
[root@k8smaster test]# docker rmi -f hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
[root@k8smaster test]# docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

删除所有的镜像:

[root@k8smaster test]# docker rmi $(docker images -q)

3、容器(container)操作

运行容器:

// -d 后台运行 -it交互模式  -p端口映射 --name命名
[root@k8smaster io-cached]# docker run --privileged --name=App -itd feisky/app:io-cached
742cd266966a35af9088b842c4f607e767a8578b7feb2d29ccf0154986e56f05

容器运行日志查看(用于验证容器是否已经运行):

[root@k8smaster io-cached]# docker logs app
Reading data from disk /dev/sda2 with buffer size 33554432
Time used: 0.410266 s to read 33554432 bytes
Time used: 0.011844 s to read 33554432 bytes
Time used: 0.011292 s to read 33554432 bytes
Time used: 0.011079 s to read 33554432 bytes
Time used: 0.011068 s to read 33554432 bytes
Time used: 0.010529 s to read 33554432 bytes
Time used: 0.011277 s to read 33554432 bytes

查看运行中的容器:

[root@k8smaster io-cached]# docker ps
CONTAINER ID   IMAGE                  COMMAND   CREATED         STATUS         PORTS     NAMES
5017ff0bc9a6   feisky/app:io-direct   "/app"    5 minutes ago   Up 5 minutes             app

暂停、重启、删除容器:

[root@k8smaster io-cached]# docker stop app
app
[root@k8smaster io-cached]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@k8smaster io-cached]# docker start app
app
[root@k8smaster io-cached]# docker ps
CONTAINER ID   IMAGE                  COMMAND   CREATED         STATUS         PORTS     NAMES
742cd266966a   feisky/app:io-cached   "/app"    3 minutes ago   Up 4 seconds             app
[root@k8smaster io-cached]# docker rm -f app
app
[root@k8smaster io-cached]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

停止或删除所有容器:

[root@k8smaster io-cached]# docker stop $(docker ps -qa)

[root@k8smaster io-cached]# docker rm -f $(docker ps -aq)
[root@k8smaster io-cached]# docker rm -f $(docker stop $(docker ps -q))

4、进入交互模式

[root@k8smaster io-cached]# docker exec -it app /bin/bash
[root@k8smaster io-cached]# docker exec -it app /bin/sh

分享到:
标签:docker
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定