当前位置:   article > 正文

decker容器部署及常用操作_decker 命令

decker 命令

- docker部署

先到阿里云下载对应的yum源和epel源

[root@cxr ~]# cd /etc/yum.repos.d/     //进到yum目录
[root@cxr yum.repos.d]# ll
总用量 8
-rw-r--r--. 1 root root 160 4月  17 04:47 cxr.repo
-rw-r--r--. 1 root root 358 4月  17 03:46 redhat.repo
[root@cxr yum.repos.d]# rm -rf *        //删除所有的文件
[root@cxr yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo       //下载阿里云的centos8的yum源  这个要看系统型号在下载对应的版本。
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   8723      0 --:--:-- --:--:-- --:--:--  8723
[root@cxr yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo      
[root@cxr yum.repos.d]# dnf clean all        //清理一下缓存
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 文件已删除
[root@cxr yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm        //下载阿里云epel8的源
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
CentOS-8.5.2111 - Base - mirrors.aliyun.com          2.7 MB/s | 4.6 MB     00:01    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com         23 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com     2.1 MB/s | 8.4 MB     00:04    
epel-release-latest-8.noarch.rpm                     159 kB/s |  23 kB     00:00    
依赖关系解决。
=====================================================================================
 软件包                架构            版本              仓库                   大小
=====================================================================================
安装:
 epel-release          noarch          8-15.el8          @commandline           23 k

事务概要
=====================================================================================
安装  1 软件包

总计:23 k
安装大小:32 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                      1/1 
  安装    : epel-release-8-15.el8.noarch                                         1/1 
  运行脚本: epel-release-8-15.el8.noarch                                         1/1 
  验证    : epel-release-8-15.el8.noarch                                         1/1 
Installed products updated.

已安装:
  epel-release-8-15.el8.noarch                                                       

完毕!
//将 repo 配置中的地址替换为阿里云镜像站地址
[root@cxr yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@cxr yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@cxr yum.repos.d]# dnf clean all    //清理一下缓存
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
17 文件已删除
[root@cxr yum.repos.d]# dnf makecache         //重建一下缓存
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
CentOS-8.5.2111 - Base - mirrors.aliyun.com          2.6 MB/s | 4.6 MB     00:01    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com         25 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com     1.6 MB/s | 8.4 MB     00:05    
Extra Packages for Enterprise Linux Modular 8 - x86_ 1.0 MB/s | 1.0 MB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64       2.1 MB/s |  11 MB     00:05    
元数据缓存已建立。
[root@cxr yum.repos.d]# cat /etc/redhat-release     //查看一下自己的系统。按照对应的系统来下载对应的源
Red Hat Enterprise Linux release 8.2 (Ootpa)

[root@cxr yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo    //下载docker-ce这个包
--2022-04-24 02:42:48--  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.36.224.212, 119.36.224.207, 119.36.224.211, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.36.224.212|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2081 (2.0K) [application/octet-stream]
正在保存至: “docker-ce.repo”

docker-ce.repo        100%[======================>]   2.03K  --.-KB/s  用时 0s      

2022-04-24 02:42:49 (47.0 MB/s) - 已保存 “docker-ce.repo” [2081/2081])
[root@cxr yum.repos.d]# ls         //可以看到已经下载成功了
CentOS-Base.repo  epel-modular.repo  epel-testing-modular.repo  redhat.repo
docker-ce.repo    epel.repo          epel-testing.repo

[root@cxr ~]# dnf list all | grep docker      //查看一下是否有docker,这里显示已经有了
containerd.io.x86_64                                              1.5.11-3.1.el8                                         docker-ce-stable
docker-ce.x86_64                                                  3:20.10.14-3.el8                                       docker-ce-stable
docker-ce-cli.x86_64                                              1:20.10.14-3.el8                                       docker-ce-stable
docker-ce-rootless-extras.x86_64                                  20.10.14-3.el8                                         docker-ce-stable
docker-compose-plugin.x86_64                                      2.3.3-3.el8                                            docker-ce-stable
docker-scan-plugin.x86_64                                         0.17.0-3.el8                                           docker-ce-stable

[root@cxr ~]# yum -y install docker-ce      //安装docker-ce。过程已省略

[root@cxr ~]# systemctl enable --now docker    //设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@cxr ~]# systemctl status docker    //查看一下状态
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: d>
   Active: active (running) since Sun 2022-04-24 03:46:41 EDT; 36s ago
     Docs: https://docs.docker.com
 Main PID: 227833 (dockerd)
    Tasks: 8
   Memory: 35.6M
   CGroup: /system.slice/docker.service
           └─227833 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/container>

4月 24 03:46:39 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:39.977323464>
4月 24 03:46:39 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:39.977353921>
4月 24 03:46:39 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:39.977671204>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.371677880>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.516457175>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.685898109>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.722918639>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.723327472>
4月 24 03:46:41 cxr.example.com dockerd[227833]: time="2022-04-24T03:46:41.751598841>
4月 24 03:46:41 cxr.example.com systemd[1]: Started Docker Application Container Eng>
[root@cxr ~]# ls /etc/docker/        //在这个目录查看有没有这个文件
key.json
 //配置镜像加速器,使用阿里云的镜像加速器,在控制台中找到容器服务下面的镜像加速器。然后点击centos.将下面的括号中的代码复制到daemon.json里面
{
[root@cxr ~]# cd /etc/docker/
[root@cxr docker]# vim daemon.json
{
 "registry-mirrors": ["https://hzlytjqu.mirror.aliyuncs.com"]
}
[root@cxr docker]# systemctl daemon-reload 
[root@cxr docker]# systemctl restart docker
//查看docker的运行环境
[root@cxr docker]# docker info 
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-193.el8.x86_64
 Operating System: Red Hat Enterprise Linux 8.2 (Ootpa)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.664GiB
 Name: cxr.example.com
 ID: WBHA:C2VE:GF45:GHWP:CMTJ:ZERC:IEQ5:HW33:MNTO:QYGZ:L4Y6:TTUL
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://hzlytjqu.mirror.aliyuncs.com/
 Live Restore Enabled: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • docker的常用命令

  • docker镜像中可以拉取里面的镜像
[root@cxr ~]# docker version          //查看客户端和服务器的版本号等等
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:47:44 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:46:10 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
//查看httpd镜像
[root@cxr ~]# docker search httpd     //在 Docker 中心搜索镜像
NAME                                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
httpd                                   The Apache HTTP Server Project                  3975      [OK]       
centos/httpd-24-centos7                 Platform for running Apache httpd 2.4 or bui…   44                   

//列出所有镜像
[root@cxr ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
//从注册表中拉取镜像或存储库
[root@cxr ~]# docker pull httpd:2.4.53
2.4.53: Pulling from library/httpd
1fe172e4850f: Pull complete 
e2fa1fe9b1ec: Pull complete 
60dd7398e74e: Pull complete 
ea2ca81c6d4c: Pull complete 
f646c69a26ec: Pull complete 
Digest: sha256:e02a2ef36151905c790efb0a8472f690010150f062639bd8c0760e7b1e884c07
Status: Downloaded newer image for httpd:2.4.53
docker.io/library/httpd:2.4.53
//创建新的容器
[root@cxr ~]# docker create --name web -p 80:80 httpd    //看不懂的话可以--help
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
a2abf6c4d29d: Pull complete 
dcc4698797c8: Pull complete 
41c22baa66ec: Pull complete 
67283bbdd4a0: Pull complete 
d982c879c57e: Pull complete 
Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Status: Downloaded newer image for httpd:latest
094366ec34baa9033349ddf290572411ee5b8573e6e3f26d43478675ce70b818

//列出所有容器
[root@cxr ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED         STATUS    PORTS     NAMES
094366ec34ba   httpd     "httpd-foreground"   4 minutes ago   Created             web

//启动容器
[root@cxr ~]# docker start web
web
//停止容器
[root@cxr ~]# docker stop web
web
//重启容器
[root@cxr ~]# docker restart web
web
//杀死正在运行的容器
[root@cxr ~]# docker kill web 
web
[root@cxr ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS                       PORTS     NAMES
094366ec34ba   httpd     "httpd-foreground"   17 minutes ago   Exited (137) 6 seconds ago             web
//查看容器的日志
[root@cxr ~]# docker logs web 
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 09:00:33.215331 2022] [mpm_event:notice] [pid 1:tid 140519505456448] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 09:00:33.215782 2022] [core:notice] [pid 1:tid 140519505456448] AH00094: Command line: 'httpd -D FOREGROUND'
172.17.0.1 - - [24/Apr/2022:09:03:02 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [24/Apr/2022:09:03:02 +0000] "GET /favicon.ico HTTP/1.1" 404 196
172.17.0.1 - - [24/Apr/2022:09:03:53 +0000] "-" 408 -
[Sun Apr 24 09:06:07.695281 2022] [mpm_event:notice] [pid 1:tid 140519505456448] AH00492: caught SIGWINCH, shutting down gracefully
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 09:10:13.075379 2022] [mpm_event:notice] [pid 1:tid 140581477367104] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 09:10:13.075591 2022] [core:notice] [pid 1:tid 140581477367104] AH00094: Command line: 'httpd -D FOREGROUND'
[Sun Apr 24 09:10:26.949510 2022] [mpm_event:notice] [pid 1:tid 140581477367104] AH00492: caught SIGWINCH, shutting down gracefully
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 09:10:28.890176 2022] [mpm_event:notice] [pid 1:tid 140573478456640] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 09:10:28.890535 2022] [core:notice] [pid 1:tid 140573478456640] AH00094: Command line: 'httpd -D FOREGROUND'

//删除容器
[root@cxr ~]# docker rm -f web 
web
[root@cxr ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

//在新容器中运行命令
[root@cxr ~]# docker run -it --name test busybox /bin/sh
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
5cc84ad355aa: Pull complete 
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Downloaded newer image for busybox:latest
/ # 
//附加到运行容器
[root@cxr ~]# docker attach test 
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # 

//在正在运行的容器中运行命令
[root@cxr ~]# docker exec -i -t  test /bin/sh
/ # 

//查看有关 Docker 对象的低级信息
[root@cxr ~]# docker inspect test | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 以上就是docker的一些常用命令
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/74050
推荐阅读
相关标签
  

闽ICP备14008679号