docker簡介以及windows安裝&linux離線安裝docker


  docker官網:https://www.docker.com/

  docker官網圖標如下:

    

  docker命令大全參考菜鳥教程:https://www.runoob.com/docker/docker-command-manual.html

docker鏡像倉庫地址:

(1)DaoCloud 道客網絡: https://hub.daocloud.io/

(2)網易(需要登陸):https://c.163yun.com/hub#/m/home/ 

(3)阿里雲(需要登陸):https://cr.console.aliyun.com/cn-beijing/instances/images

 

1.docker簡介

  Docker 是一個開源的應用容器引擎,可以讓開發者打包他們的應用以及依賴包到一個輕量級、可移植的容器中,然后發布到任何流行的 Linux 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,相互之間不會有任何接口(類似 iPhone 的 app),更重要的是容器性能開銷極低。

1.什么是docker

1.docker是一個容器平台軟件;

2.Docker公司開發、開源、托管在github上

3.跨平台,支持linux、windows、macos 

2.應用場景

Web 應用的自動化打包和發布。
自動化測試和持續集成、發布。
在服務型環境中部署和調整數據庫或其他的后台應用。

3.優點

  Docker 是一個用於開發,交付和運行應用程序的開放平台。Docker 使您能夠將應用程序與基礎架構分開,從而可以快速交付軟件。借助 Docker,您可以與管理應用程序相同的方式來管理基礎架構。通過利用 Docker 的方法來快速交付,測試和部署代碼,您可以大大減少編寫代碼和在生產環境中運行代碼之間的延遲。

4.解決問題

1.環境不一致:經常看到java依賴外部環境,經常見到的程序員說的我本地沒問題啊。比如說JDK8編譯的程序放到另一台機器,機器上面的JDK是7就會報最低版本錯誤。docker把操作系統,jdk,tomcat,代碼,配置全部放到集裝箱里.再打包放到鯨魚上,由鯨魚給我們送到服務器上,在我的機器上怎么運行,在別的機器上也怎么運行.不會有任何的問題.一句話就是docker解決了運行環境不一致所帶來的問題。

2.不同程序直接依賴性太強,容易受其他程序影響

  docker每個容器都是一個進程,都可以看做一個虛擬的主機。docker在啟動的時候就限定好一個容器最大使用的CPU硬盤,如果超過了,就會殺掉對應進程。

2.docker標准化可以快速擴展、彈性伸縮。

5.docker核心技術

   “鏡像”就好比是面向對象中的“類”,“容器”就好比“類”創建的“對象”。在面向對象中,“類”定義了各種屬性,“類”可以實例化出多個“對象”;而在Docker中,“鏡像”定義了各種配置信息,它可以實例化出多個“容器”。“容器”就是一台可以運行的“虛擬機”。

1.docker鏡像Image

  docker鏡像實際上是文件,文件就肯定存在本地。docker文件機制依賴於linux的聯合文件系統(Union File System):它可以把多個目錄(也叫分支)內容聯合掛載到同一個目錄下,而目錄的物理位置是分開的。UnionFS允許只讀和可讀寫目錄並存,就是說可同時刪除和增加內容。如下:(test1看做第一層、test2看做第二層,test就可以看到兩個目錄的所有文件)

 

  docker的鏡像分層如下,Image層是鏡像文件,可以是tomcat、jdk、我們的應用程序等等,鏡像層是只讀的。

2.docker容器

  docker的容器實際上就是一個進程,為了便於理解可以將容器想象為一個虛擬機。docker的容器層(最上層)是可讀可寫的,但是鏡像層是只讀的,如果我們需要需要鏡像層文件的時候,我們實際上是將文件拷貝到容器層,每次找的時候都是從頂層開始找的。由於容器的最上一層是可以修改的,鏡像是不能修改的,這樣就能保證鏡像可以生成多個容器獨立運行,沒有任何干擾。

3.docker倉庫

  我們構建鏡像的目的是為了將應用在其他機器運行,所以就需要將鏡像推到倉庫。這有點類似於git的倉庫,可以將代碼推到倉庫,其他機子隨意拉下來。

  docker自己提供了倉庫,網速比較慢。所以需要用到鏡像加速器。

  網易倉庫地址:https://c.163.com/hub#/home

2.windows安裝docker

  windows下安裝的docker實際上是虛擬了一個linux環境,建議還是linux上直接使用docker。

1.下載安裝包

win7、win8 等需要利用 docker toolbox 來安裝,下載地址

 2.運行安裝

   直接全部下一步即可。下載完成桌面出現三個快捷方式。

 3.初始化docker工具

  【此時還未進行注冊和啟動虛擬機,若直接采用系統CMD命令窗口執行docker命令會產生錯誤。】

打開Docker Quickstart Terminal。然后等待其初始化完成即可(可以關閉窗口)。

 

補充:我在打開的時候報錯windows 正在查找bash.exe。如果想親自查找文件,請點擊“瀏覽”

  原因是我在之前已經安裝了git。解決辦法:修改下面目標為自己的git地址

 

 補充:我在再次點擊的時候cmd窗口提示looks like something went wrong in step ‘looking for vboxmanage.exe’

  原因是DOCKER_TOOLBOX_INStALL_PATH和VBOX_MSI_INSTALL_PATH這兩個環境變量並沒有生效,雖然你能看到它們,但是程序卻看不到它們。你可以打開cmd然后輸入set DOCKER_TOOLBOX_INStALL_PATH和set VBOX_MSI_INSTALL_PATH命令查看一下(我查看的時候有值)。解決辦法:重啟機器。

4.查看版本

C:\Users\Administrator>docker version
Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24302
 Built: Fri Mar 23 08:31:36 2018
 OS/Arch:       windows/amd64
 Experimental:  false
 Orchestrator:  swarm

Server: Docker Engine - Community
 Engine:
  Version:      19.03.5
  API version:  1.40 (minimum version 1.12)
  Go version:   go1.12.12
  Git commit:   633a0ea838
  Built:        Wed Nov 13 07:28:45 2019
  OS/Arch:      linux/amd64
  Experimental: false
 containerd:
  Version:      v1.2.10
  GitCommit:            b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:      1.0.0-rc8+dev
  GitCommit:            3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:      0.18.0
  GitCommit:            fec3683

也可以使用docker查看支持id命令,如下:

C:\Users\Administrator>docker

Usage:  docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "C:\\Users\\Administrator\\.docker")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "C:\\Users\\Administrator\\.docker\\machine\\machines\\default\\ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "C:\\Users\\Administrator\\.docker\\machine\\machines\\default\\cert.pem")
      --tlskey string      Path to TLS key file (default
                           "C:\\Users\\Administrator\\.docker\\machine\\machines\\default\\key.pem")
      --tlsverify          Use TLS and verify the remote (default true)
  -v, --version            Print version information and quit

Management Commands:
  config      Manage Docker configs
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

 

  到此docker安裝成功。

 

總結:

  再次查看docker官網的圖標,如下:

(1)鏡像可以看做上面集裝箱,倉庫就是超級碼頭,容器就是我們運行程序的地方。docker運行程序的過程就是去倉庫把鏡像拉到(pull)本地,然后用一條命令把鏡像運行(run)起來變成容器。

(2)docker中有3個重要概念:

build:構建,就是構建鏡像.

ship:運輸,運輸鏡像,從倉庫和主機運輸.

run:運行的鏡像就是一個容器.

build,ship,run和鏡像,倉庫,容器是一一對應的.

 

補充:windows上面的docker是基於虛擬的linux環境的,所以每次啟動都需要打開Oracle VM VirtualBox

補充:windows鏡像存在C盤,下載的鏡像多了 之后會造成C盤內存不足。解決辦法:

  默認情況下,docker-machine創建的虛擬機文件,是保存在C盤的C:\Users\用戶名\.docker\machine\machines\default 目錄下的,如果下載和使用的鏡像過多,那么必然導致該文件夾膨脹過大,如果C盤比較吃緊,那么我們就得考慮把該虛擬機移到另一個盤上

(1)停止default虛擬機器

$ docker-machine stop default
Stopping "default"...
Machine "default" was stopped.

(2)打開VirtualBox,選擇“管理”菜單下的“虛擬介質管理”,我們可以看到Docker虛擬機用的虛擬硬盤的文件disk。

(3)選中“disk”,然后點擊菜單中的“移動”命令,根據向導,把當前的disk移動到另一個盤上面去。

  移走只會可以看到C盤空間瞬間變大了。

(4)選中default機器,然后設置-》存儲可以查看disk的位置,如下:

 

3.linux下離線安裝docker

  centos78離線安裝可以用docker 1.8或者1.91.81.9要求內核為3.10.0以上。如果內核是3.10.0以下,需要手動下載rpm包進行安裝。

(1)查看內核方式:

[root@localhost ocrtemplate]# cat /proc/version 
Linux version 2.6.32-696.el6.x86_64 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Feb 21 00:53:17 EST 2017

或者:

[root@localhost ocrtemplate]# uname -a
Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Feb 21 00:53:17 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

(2)查看發行版方式:

[root@localhost ocrtemplate]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Kernel \r on an \m

或者:(只適用於redhat系列的linux)

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

 

 

====centos78離線安裝docker (內核在3.10.0以上)======

1.准備文件

下載gz包,https://download.docker.com/linux/static/stable/x86_64/ 

2.上傳到linux服務器進行解壓安裝

1.解壓

docker-18.03.1-ce.tgz  zdtesseract.tar
[root@localhost docker]# ls
docker-18.03.1-ce.tgz  zdtesseract.tar
[root@localhost docker]# tar -zxvf ./docker-18.03.1-ce.tgz 
docker/
docker/dockerd
docker/docker-proxy
docker/docker-containerd
docker/docker-runc
docker/docker-init
docker/docker-containerd-shim
docker/docker
docker/docker-containerd-ctr

 

2.將文件復制到 /usr/bin/

cp docker/* /usr/bin/

 

3.使用命令來開啟docker守護進程:

sudo dockerd &

  & 放在命令后面表示設置此進程為后台進程。默認情況下,進程是前台進程,這時此進程(命令執行相當於本質是開啟一個進程)就把Shell給占據了,我們無法進行其他操作,對於那些沒有交互的進程,很多時候,我們希望將其在后台啟動,可以在啟動參數的時候加一個'&'實現這個目的。
  出現下面證明dockerd啟動成功,可以ctrl+c:

 

 4.查看docker版本:

[root@localhost docker]# docker -v
Docker version 18.03.1-ce, build 9ee9f40

 

5.運行docker run hello-world (直接運行會查找鏡像,不存在會自動下載)

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest
INFO[0240] shim docker-containerd-shim started           address="/containerd-shim/moby/49512a9df6f3d3fce6d954ce3fa99bf6dc9f368bb4bbafc714dd4f383a57a4d5/shim.sock" debug=false module="containerd/tasks" pid=6349

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

INFO[0241] shim reaped                                   id=49512a9df6f3d3fce6d954ce3fa99bf6dc9f368bb4bbafc714dd4f383a57a4d5 module="containerd/tasks"
INFO[2020-06-02T04:22:11.127666142-04:00] ignoring event                                module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"

  上面親測,centos8和7中可以安裝。

 

  redhat6.9內核為3.10.0以下無法使用:

[root@localhost docker]# cat /etc/redhat-release   #查看服務器版本
Red Hat Enterprise Linux Server release 6.9 (Santiago)
[root@localhost docker]# cat /proc/version   #查看內核版本
Linux version 2.6.32-696.el6.x86_64 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Feb 21 00:53:17 EST 2017
[root@localhost docker]# uname -a
Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Feb 21 00:53:17 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

 

====redhat6.9安裝docker(內核3.10.0以下)======

1.依賴的rpm

 lxc-libs-1.0.9-1.el6.x86_64.rpm
 lua-alt-getopt-0.7.0-1.el6.noarch.rpm
 lua-filesystem-1.4.2-1.el6.x86_64.rpm
 lua-lxc-1.0.9-1.el6.x86_64.rpm  
 lxc-1.0.9-1.el6.x86_64.rpm  
 docker-io-1.7.1-2.el6.x86_64.rpm

 device-mapper-libs-1.02.117-12.el6.i686.rpm
 device-mapper-libs-1.02.117-12.el6.x86_64.rpm

2.可以將依賴打成gz包,如下:

 3.將docker.tar.gz上傳到服務器

4. 解壓

tar -zxvf ./docker.tar.gz

5.執行如下命令安裝:

rpm -ivh lxc-libs-1.0.9-1.el6.x86_64.rpm
rpm -ivh lua-alt-getopt-0.7.0-1.el6.noarch.rpm
rpm -ivh lua-filesystem-1.4.2-1.el6.x86_64.rpm
rpm -ivh lua-lxc-1.0.9-1.el6.x86_64.rpm 
rpm -ivh lxc-1.0.9-1.el6.x86_64.rpm 
rpm -ivh docker-io-1.7.1-2.el6.x86_64.rpm

rpm -ivh device-mapper-libs-1.02.117-12.el6.i686.rpm --force --nodeps
rpm -ivh device-mapper-libs-1.02.117-12.el6.x86_64.rpm --force --nodeps

6. 啟動docker

service docker start(用來生成cgroup隔離環境)
docker -d &

7. 測試

[root@localhost ocrtemplate]# docker -v
Docker version 1.7.1, build 786b29d/1.7.1
[root@localhost ocrtemplate]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM