Docker基础指令

Docker基础指令,第1张

Docker基础指令

目录
  • 一、基础命令
    • 1,查看docker版本
    • 2,查看docker命令
    • 3,查看docker服务端与客户端版本详情
    • 4,启动docker进程
    • 5,关闭docker进程
    • 6,重启docker进程
    • 7,查看docker运行状态
    • 8,关闭防火墙
  • 二、docker镜像相关命令
    • 1,查看本地镜像
    • 2,搜索镜像
    • 3,拉取镜像
      • (1)默认最新版本
      • (2)拉取特定版本
    • 4,删除镜像
    • 5,有镜像之后,可以创建容器
    • 6,查看容器
      • (1)查看在运行的容器
      • (2)查看所有容器
    • 7,运行容器
      • (1)以容器名称启动
      • (2)以容器ID启动
    • 8,停止容器运行
      • (1)以容器名称停止
      • (2)以容器ID停止
    • 9,进入容器内部
    • 10,退出容器
    • 11,删除容器
      • (1)删除正在运行中的容器
      • (2)删除没有在运行的容器
    • 12,删除所有容器
      • (1)停止所有容器运行并删除
      • (2)强行删除所有容器

一、基础命令 1,查看docker版本

docker -v

[root@localhost ServerAgent-2.2.3]# docker -v
Docker version 19.03.13, build 4484c46d9d
2,查看docker命令

docker --help

3,查看docker服务端与客户端版本详情

docker version

[root@localhost ServerAgent-2.2.3]# docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:03:45 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:02:21 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

4,启动docker进程

systemctl start docker

[root@localhost ServerAgent-2.2.3]# systemctl start docker
5,关闭docker进程

systemctl stop docker

[root@localhost ServerAgent-2.2.3]# systemctl stop docker
6,重启docker进程

systemctl restart docker

[root@localhost ServerAgent-2.2.3]# systemctl restart docker
7,查看docker运行状态

systemctl status docker

[root@localhost ServerAgent-2.2.3]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 三 2021-10-20 11:25:37 CST; 1min 47s ago
     Docs: https://docs.docker.com
 Main PID: 43526 (dockerd)
    Tasks: 8
   Memory: 40.7M
   CGroup: /system.slice/docker.service
           └─43526 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.601924807+08:00" level=i...rpc
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.601945742+08:00" level=i...rpc
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.614057677+08:00" level=i...y2"
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.619438786+08:00" level=i...t."
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.833160897+08:00" level=i...ss"
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.940314390+08:00" level=i...e."
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.967448679+08:00" level=i....13
10月 20 11:25:36 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:36.967568661+08:00" level=i...on"
10月 20 11:25:37 localhost.localdomain dockerd[43526]: time="2021-10-20T11:25:37.001763143+08:00" level=i...ck"
10月 20 11:25:37 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

8,关闭防火墙

systemctl stop firewalld

[root@localhost ServerAgent-2.2.3]# systemctl stop firewalld
二、docker镜像相关命令 1,查看本地镜像

docker images

[root@localhost ServerAgent-2.2.3]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
2,搜索镜像

显示的是下载源里面的镜像
docker search tomcat

[root@localhost ServerAgent-2.2.3]# docker search tomcat
NAME                          DEscriptION                                     STARS               OFFICIAL            AUTOMATED
tomcat                        Apache Tomcat is an open source implementati…   3155                [OK]                
tomee                         Apache TomEE is an all-Apache Java EE certif…   93                  [OK]                
dordoka/tomcat                Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   58                                      [OK]
kubeguide/tomcat-app          Tomcat image for Chapter 1                      31                                      
consol/tomcat-7.0             Tomcat 7.0.57, 8080, "admin/admin"              18                                      [OK]
cloudesire/tomcat             Tomcat server, 6/7/8                            15                                      [OK]
aallam/tomcat-mysql           Debian, Oracle JDK, Tomcat & MySQL              13                                      [OK]
arm32v7/tomcat                Apache Tomcat is an open source implementati…   11                                      
rightctrl/tomcat              CentOS , Oracle Java, tomcat application ssl…   7                                       [OK]
arm64v8/tomcat                Apache Tomcat is an open source implementati…   6                                       
maluuba/tomcat7-java8         Tomcat7 with java8.                             6                                       
unidata/tomcat-docker         Security-hardened Tomcat Docker container.      5                                       [OK]
amd64/tomcat                  Apache Tomcat is an open source implementati…   3                                       
jelastic/tomcat               An image of the Tomcat Java application serv…   2                                       
oobsri/tomcat8                Testing CI Jobs with different names.           2                                       
cfje/tomcat-resource          Tomcat Concourse Resource                       2                                       
fabric8/tomcat-8              Fabric8 Tomcat 8 Image                          2                                       [OK]
chenyufeng/tomcat-centos      tomcat基于centos6的镜像                              1                                       [OK]
picoded/tomcat7               tomcat7 with jre8 and MANAGER_USER / MANAGER…   1                                       [OK]
99taxis/tomcat7               Tomcat7                                         1                                       [OK]
camptocamp/tomcat-logback     Docker image for tomcat with logback integra…   1                                       [OK]
ppc64le/tomcat                Apache Tomcat is an open source implementati…   1                                       
softwareplant/tomcat          Tomcat images for jira-cloud testing            0                                       [OK]
secoresearch/tomcat-varnish   Tomcat and Varnish 5.0                          0                                       [OK]
s390x/tomcat                  Apache Tomcat is an open source implementati…   0              
3,拉取镜像 (1)默认最新版本

docker pull tomcat

[root@localhost ServerAgent-2.2.3]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
bb7d5a84853b: Pull complete 
f02b617c6a8c: Pull complete 
d32e17419b7e: Pull complete 
c9d2d81226a4: Pull complete 
fab4960f9cd2: Pull complete 
da1c1e7baf6d: Pull complete 
79b231561270: Pull complete 
7d337880d8b4: Pull complete 
2df65a31be06: Pull complete 
10cbf519de23: Pull complete 
Digest: sha256:7c30d3c92b191ec2b84f64be99326f9c83a4a4e079c899ee4d0a9a41abca8406
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
(2)拉取特定版本

我这里以v7版本为例
docker pull tomcat:7

[root@localhost ServerAgent-2.2.3]# docker pull tomcat:7
4,删除镜像

docker rmi

[root@localhost ServerAgent-2.2.3]# docker rmi
5,有镜像之后,可以创建容器

docker create --name=myTomcat tomcat

[root@localhost ServerAgent-2.2.3]# docker create --name=myTomcat tomcat
1b635b80f9a96cc8498baa58cf213eaf70308883f90146abb42ee062a55fa3e7
6,查看容器 (1)查看在运行的容器

docker ps

[root@localhost ServerAgent-2.2.3]# docker ps
ConTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
(2)查看所有容器

注意:容器信息里包括ID和名称
docker ps -a

[root@localhost ServerAgent-2.2.3]# docker ps -a
ConTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
1b635b80f9a9        tomcat              "catalina.sh run"   22 minutes ago      Created                                 myTomcat
7,运行容器 (1)以容器名称启动

docker start 容器名

[root@localhost ServerAgent-2.2.3]# docker start myTomcat
myTomcat
(2)以容器ID启动

模糊匹配,一般输前2-3位就可以
docker start 容器ID

[root@localhost ServerAgent-2.2.3]# docker start 1b
1b
8,停止容器运行 (1)以容器名称停止

docker stop 容器名

[root@localhost ServerAgent-2.2.3]# docker stop myTomcat
myTomcat
(2)以容器ID停止

模糊匹配,一般输前2-3位就可以
docker stop 容器ID

[root@localhost ServerAgent-2.2.3]# docker stop 1b
1b
9,进入容器内部

(容器内部也是一个微型的linux系统,很多简单的指令都可以用)
docker exec -it 容器名或容器ID /bin/bash

[root@localhost ServerAgent-2.2.3]# docker exec -it 1b /bin/bash
root@1b635b80f9a9:/usr/local/tomcat# 
10,退出容器

exit

root@1b635b80f9a9:/usr/local# exit
exit
[root@localhost ServerAgent-2.2.3]#
11,删除容器 (1)删除正在运行中的容器

docker rm -f 容器名或容器ID

[root@localhost ServerAgent-2.2.3]# docker rm -f 1b
(2)删除没有在运行的容器

docker rm -f 容器名或容器ID

[root@localhost ServerAgent-2.2.3]# docker rm -f 1b
12,删除所有容器 (1)停止所有容器运行并删除

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

[root@localhost ServerAgent-2.2.3]# docker stop $(docker ps -a -q)
1b635b80f9a9
[root@localhost ServerAgent-2.2.3]# docker rm $(docker ps -a -q)
(2)强行删除所有容器

docker rm -f $(docker ps -a -q)

[root@localhost ServerAgent-2.2.3]# docker rm -f $(docker ps -a -q)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4666670.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-06
下一篇 2022-11-06

发表评论

登录后才能评论

评论列表(0条)

保存