日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
詳解Docker平臺基本使用方法

Docker 是一個開源的應(yīng)用容器引擎,讓開發(fā)者可以打包他們的應(yīng)用以及依賴包到一個可移植的容器中,然后發(fā)布到任何流行的 Linux 機器上,也可以實現(xiàn)虛擬化,本篇文章重點為大家講解一下Docker平臺基本使用方法。

公司主營業(yè)務(wù):成都做網(wǎng)站、成都網(wǎng)站設(shè)計、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出鎮(zhèn)沅免費做網(wǎng)站回饋大家。

開啟動網(wǎng)絡(luò)轉(zhuǎn)發(fā)功能,默認(rèn)會自動開啟

[root@Docker  ]# vim /etc/sysctl.conf #插入以下內(nèi)容
net.ipv4.ip_forward = 1
[root@Docker  ]# sysctl -p #生效
net.ipv4.ip_forward = 1
[root@Docker  ]# cat /proc/sys/net/ipv4/ip_forward
1

例 1:運行一個 container 并加載鏡像 centos,運行起來這個實例后,在實例中執(zhí)行 /bin/bash 命令

docker 常用參數(shù):
run 運行
-i 以交互模式運行容器,通常與 -t 同時使用
-t 為容器重新分配一個偽輸入終端,通常與 -i 同時使用
[root@Docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        4 months ago        237MB
[root@Docker ~]# docker run -it centos:latest /bin/bash  #啟動一個實例,秒級響應(yīng)

[root@efb4af688330 /]# ls
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr

[root@efb4af688330 /]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

安裝軟件

[root@0a297ff99af8 /]# yum install -y httpd
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream                      5.7 MB/s | 7.0 MB     00:01    
CentOS-8 - Base                           2.2 MB/s | 2.2 MB     00:00    
CentOS-8 - Extras                         8.1 kB/s | 5.9 kB     00:00    
Dependencies resolved.
==========================================================================
Package     Arch   Version                               Repo       Size
==========================================================================
Installing:
httpd       x86_64 2.4.37-16.module_el8.1.0+256+ae790463 AppStream 1.7 M
Installing dependencies:
apr         x86_64 1.6.3-9.el8                           AppStream 125 k
apr-util    x86_64 1.6.1-6.el8                           AppStream 105 k
centos-logos-httpd
            noarch 80.5-2.el8                            AppStream  24 k
httpd-filesystem
            noarch 2.4.37-16.module_el8.1.0+256+ae790463 AppStream  35 k
httpd-tools x86_64 2.4.37-16.module_el8.1.0+256+ae790463 AppStream 103 k
mod_http2   x86_64 1.11.3-3.module_el8.1.0+213+acce2796  AppStream 158 k
brotli      x86_64 1.0.6-1.el8                           BaseOS    323 k
mailcap     noarch 2.1.48-3.el8                          BaseOS     39 k
Installing weak dependencies:
apr-util-bdb
            x86_64 1.6.1-6.el8                           AppStream  25 k
apr-util-openssl
            x86_64 1.6.1-6.el8                           AppStream  27 k
Enabling module streams:
httpd              2.4                                                  

Transaction Summary
==========================================================================
Install  11 Packages

Total download size: 2.6 M
Installed size: 8.1 M
Downloading Packages:
(1/11): apr-util-bdb-1.6.1-6.el8.x86_64.r 142 kB/s |  25 kB     00:00    A
(2/11): apr-1.6.3-9.el8.x86_64.rpm        588 kB/s | 125 kB     00:00    
(3/11): apr-util-openssl-1.6.1-6.el8.x86_ 346 kB/s |  27 kB     00:00    
(4/11): apr-util-1.6.1-6.el8.x86_64.rpm   340 kB/s | 105 kB     00:00    
(5/11): centos-logos-httpd-80.5-2.el8.noa 187 kB/s |  24 kB     00:00    
(6/11): httpd-filesystem-2.4.37-16.module 398 kB/s |  35 kB     00:00    
(7/11): mod_http2-1.11.3-3.module_el8.1.0 992 kB/s | 158 kB     00:00    
(8/11): httpd-2.4.37-16.module_el8.1.0+25 4.8 MB/s | 1.7 MB     00:00    
(9/11): httpd-tools-2.4.37-16.module_el8. 387 kB/s | 103 kB     00:00    
(10/11): mailcap-2.1.48-3.el8.noarch.rpm  289 kB/s |  39 kB     00:00    
(11/11): brotli-1.0.6-1.el8.x86_64.rpm    826 kB/s | 323 kB     00:00    
--------------------------------------------------------------------------
Total                                     290 kB/s | 2.6 MB     00:09    
warning: /var/cache/dnf/AppStream-02e86d1c976ab532/packages/apr-1.6.3-9.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream                      1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
Userid     : "CentOS (CentOS Official Signing Key) "
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
 Preparing        :                                                  1/1
 Installing       : apr-1.6.3-9.el8.x86_64                          1/11
 Running scriptlet: apr-1.6.3-9.el8.x86_64                          1/11
 Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                 2/11
 Installing       : apr-util-openssl-1.6.1-6.el8.x86_64             3/11
 Installing       : apr-util-1.6.1-6.el8.x86_64                     4/11
 Running scriptlet: apr-util-1.6.1-6.el8.x86_64                     4/11
 Installing       : httpd-tools-2.4.37-16.module_el8.1.0+256+ae7    5/11
 Installing       : mailcap-2.1.48-3.el8.noarch                     6/11
 Installing       : brotli-1.0.6-1.el8.x86_64                       7/11
 Running scriptlet: httpd-filesystem-2.4.37-16.module_el8.1.0+25    8/11
 Installing       : httpd-filesystem-2.4.37-16.module_el8.1.0+25    8/11
 Installing       : centos-logos-httpd-80.5-2.el8.noarch            9/11
 Installing       : mod_http2-1.11.3-3.module_el8.1.0+213+acce27   10/11
 Installing       : httpd-2.4.37-16.module_el8.1.0+256+ae790463.   11/11
 Running scriptlet: httpd-2.4.37-16.module_el8.1.0+256+ae790463.   11/11
 Verifying        : apr-1.6.3-9.el8.x86_64                          1/11
 Verifying        : apr-util-1.6.1-6.el8.x86_64                     2/11
 Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                 3/11
 Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64             4/11
 Verifying        : centos-logos-httpd-80.5-2.el8.noarch            5/11
 Verifying        : httpd-2.4.37-16.module_el8.1.0+256+ae790463.    6/11
 Verifying        : httpd-filesystem-2.4.37-16.module_el8.1.0+25    7/11
 Verifying        : httpd-tools-2.4.37-16.module_el8.1.0+256+ae7    8/11
 Verifying        : mod_http2-1.11.3-3.module_el8.1.0+213+acce27    9/11
 Verifying        : brotli-1.0.6-1.el8.x86_64                      10/11
 Verifying        : mailcap-2.1.48-3.el8.noarch                    11/11

Installed:
 httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64                      
 apr-util-bdb-1.6.1-6.el8.x86_64                                        
 apr-util-openssl-1.6.1-6.el8.x86_64                                    
 apr-1.6.3-9.el8.x86_64                                                  
 apr-util-1.6.1-6.el8.x86_64                                            
 centos-logos-httpd-80.5-2.el8.noarch                                    
 httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch          
 httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64                
 mod_http2-1.11.3-3.module_el8.1.0+213+acce2796.x86_64                  
 brotli-1.0.6-1.el8.x86_64                                              
 mailcap-2.1.48-3.el8.noarch                                            

Complete!

退出容器

[root@efb4af688330 /]# exit
exit
[root@Docker ~]#

例 2:在 container 中啟動一個長久運行的進程,不斷向 stdin 輸出 hello world 模擬一個后臺運行的服務(wù)

docker 常用參數(shù):
-d 后臺運行容器,并返回容器 ID
-c 后面跟待完成的命令
[root@Docker ~]# docker run -d centos:latest /bin/bash -c "while true;do echo hello world;sleep 1;done"
607752360adf7e9ebfdbae01d09b2fd9ed2f350ad2d87e3e868d63144b966104
#容器的 ID

從一個容器中取日志,查看輸出的內(nèi)容

[root@Docker ~]# docker logs 607752360ad #容器的 ID 可以寫全,也可以不寫全,只要唯一就可以了
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
[root@Docker ~]#

查看正在運行的容器

[root@Docker  ]# docker ps #列出所有運行中容器
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES
607752360adf        centos:latest       "/bin/bash -c 'while…"   About a minute ago   Up About a minute                       brave_fermi

也可以使用短 ID 或 docker 實例的名字查看日志輸出

[root@Docker ~]# docker logs 607752360adf
或
[root@Docker ~]# docker logs brave_fermi
[root@Docker ~]# docker ps -a #-a 列出所有容器(包含沉睡/退出狀態(tài)的容器)
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
607752360adf        centos:latest       "/bin/bash -c 'while…"   4 minutes ago       Up 4 minutes                                   brave_fermi
0a297ff99af8        centos:latest       "/bin/bash"              7 minutes ago       Exited (1) 5 minutes ago                       ecstatic_yonath
efb4af688330        centos:latest       "/bin/bash"              9 minutes ago       Exited (0) 8 minutes ago                       epic_mcclintock

[root@Docker ~]# docker images #列出所有本地鏡像
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        4 months ago        237MB

例 3:殺死一個容器 比如:殺死一個正在后臺運行的容器

查看要殺死容器的 ID

[root@Docker ~]# docker ps -a #-a 列出所有容器(包含沉睡/退出狀態(tài)的容器);
殺死 ID 為 607752360adf 的容器
[root@Docker ~]# docker kill 607752360adf #殺死一個容器
607752360adf

查看結(jié)果

[root@Docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

例 4:啟動、停止、重啟 container 容器實例

啟動: run # 創(chuàng)建并運行 docker 實例

[root@Docker  ]# docker run -d centos:latest /bin/bash -c "while true;do echo hello world;sleep 1;done"

查看容器

[root@Docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
bea2aaa70725        centos:latest       "/bin/bash -c 'while…"   4 seconds ago       Up 3 seconds                            flamboyant_keller

關(guān)閉容器

[root@Docker ~]# docker stop bea2aaa70725
bea2aaa70725

查看

[root@Docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@Docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                        PORTS               NAMES
bea2aaa70725        centos:latest       "/bin/bash -c 'while…"   About a minute ago   Exited (137) 35 seconds ago                       flamboyant_keller
607752360adf        centos:latest       "/bin/bash -c 'while…"   9 minutes ago        Exited (137) 3 minutes ago                        brave_fermi
0a297ff99af8        centos:latest       "/bin/bash"              12 minutes ago       Exited (1) 10 minutes ago                         ecstatic_yonath
efb4af688330        centos:latest       "/bin/bash"              15 minutes ago       Exited (0) 13 minutes ago                         epic_mcclintock
[root@Docker ~]# docker start bea2aaa70725
bea2aaa70725
[root@Docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
bea2aaa70725        centos:latest       "/bin/bash -c 'while…"   2 minutes ago       Up 31 seconds                           flamboyant_keller
[root@Docker ~]# docker restart bea2aaa70725
bea2aaa70725

刪除指定 container : rm

[root@Docker ~]# docker rm bea2aaa70725
Error response from daemon: You cannot remove a running container bea2aaa707259a80c474e7d43c5648af0a5cfe16c4e50470fb6c5c84a0490d8b. Stop the container before attempting removal or force remove

解決:可以先把容器 1a63ddea6571 關(guān)閉,然后再刪除或加-f 強制刪除

[root@Docker ~]# docker rm -f bea2aaa70725
bea2aaa70725

總結(jié)

以上就是 Docker 平臺基本使用方法,希望能給大家?guī)韼椭?/p>
文章名稱:詳解Docker平臺基本使用方法
文章源于:http://www.5511xx.com/article/cosjehj.html