ITPub博客

首页 > 云计算 > > docker 安装

docker 安装

作者:浪花小雨滴 时间:2020-05-11 18:05:32 0 删除 编辑

Docker概念

Docker是开发人员和系统管理员使用容器开发,部署和运行应用程序的平台。使用Linux容器部署应用程序称为容器化,容器不是新的,但它们用于轻松部署应用程序。

容器化越来越受欢迎,因为容器是:

  • 灵活:即使是最复杂的应用也可以集装箱化
  • 轻量级:容器利用并共享主机内核
  • 可互换:您可以即时部署更新和升级
  • 便携式:您可以在本地构建,部署到云,并在任何地方运行
  • 可扩展:您可以增加并自动分发容器副本
  • 可堆叠:您可以垂直和即时堆叠服务

镜像和容器

通过运行镜像启动容器,一个镜像是一个可执行的包,其中包括运行应用程序所需的所有内容的代码,运行时的库,环境变量和配置文件等。

容器是镜像的运行时的实例,您可以使用该命令查看正在运行的容器列表docker ps,就像在Linux中一样。

容器和虚拟机

一个容器中运行在本地的 Linux上,与其它容器的共享内核。它运行在一个独立的进程,不占用任何其他可执行文件的内存,使其轻量级。

相比之下,虚拟机(VM)运行一个完整的“客户”操作系统,通过虚拟机管理程序对主机资源进行虚拟访问。通常,VM提供的环境比大多数应用程序需要的资源更多。



安装docker(centos 7)

2019-9-7 00:39:35

安装必要程序

  yum install -y yum-utils \
   device-mapper-persistent-data \
   lvm2

设置存储库

 yum-config-manager \
     --add-repo \
     https://download.docker.com/linux/centos/docker-ce.repo

其他链接:官网安装说明

安装docker-ce

 yum install docker-ce docker-ce-cli containerd.io

如果要安装指定的docker

 yum list docker-ce --showduplicates | sort -r
 yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
 [root@tangtao ~]#  yum list docker-ce --showduplicates | sort -r
  * updates: ty1.mirror.newmediaexpress.com
 Loading mirror speeds from cached hostfile
 Loaded plugins: fastestmirror
 Installed Packages
  * extras: ty1.mirror.newmediaexpress.com
  * epel: nrt.edge.kernel.org
 docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
 docker-ce.x86_64            3:19.03.2-3.el7                    @docker-ce-stable
 docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
 docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
 docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
 docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
 docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable 

启动docker

 systemctl enable docker && systemctl start docker

输出

 [root@tangtao ~]# systemctl enable docker && systemctl start docker
 Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
 [root@tangtao ~]# 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 Sat 2019-09-07 00:36:48 CST; 13s ago
      Docs: https://docs.docker.com
  Main PID: 2480 (dockerd)
     Tasks: 8
    Memory: 42.7M
    CGroup: /system.slice/docker.service
            └─2480 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
 ​
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.222859351+08:00" level=info msg="ClientConn switching b...e=grpc
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.222938750+08:00" level=info msg="pickfirstBalancer: Han...e=grpc
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.225434355+08:00" level=info msg="pickfirstBalancer: Han...e=grpc
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.265608900+08:00" level=info msg="Loading containers: start."
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.655044141+08:00" level=info msg="Default bridge (docker...dress"
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.907247851+08:00" level=info msg="Loading containers: done."
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.949361508+08:00" level=info msg="Docker daemon" commit=...9.03.2
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.949547821+08:00" level=info msg="Daemon has completed i...ation"
 Sep 07 00:36:48 tangtao dockerd[2480]: time="2019-09-07T00:36:48.988111846+08:00" level=info msg="API listen on /var/run....sock"
 Sep 07 00:36:48 tangtao systemd[1]: Started Docker Application Container Engine.
 Hint: Some lines were ellipsized, use -l to show in full.
 ​

配置镜像加速器(阿里云)

针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

 sudo mkdir -p /etc/docker
 sudo tee /etc/docker/daemon.json <<-'EOF'
 {
   "registry-mirrors": ["https://kczpkkxo.mirror.aliyuncs.com"]
 }
 EOF
 sudo systemctl daemon-reload
 sudo systemctl restart docker

helloword

 docker run hello-world
 [root@tangtao ~]#  docker run hello-world
 Unable to find image 'hello-world:latest' locally
 latest: Pulling from library/hello-world
 1b930d010525: Pull complete 
 Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
 Status: Downloaded newer image for hello-world:latest
 ​
 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/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31537575/viewspace-3165903/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-05-16

  • 博文量
    4259
  • 访问量
    39922