欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在Linux上安装docker容器

程序员文章站 2022-04-14 10:36:53
...

摘要:首先对docker 容器做初步的了解学习,请移步:http://blog.csdn.net/liguangxianbin/article/details/79459500,

                官方安装文档,请移步:https://docs.docker.com/install ,

                博主的docker博客,移步:http://blog.csdn.net/liguangxianbin/article/category/7485990 里面有我在配置docker

                          环境中出现的一些问题,以及解决方法.


docker 有两种版本,一种是 Docker EE  企业级版本,另一种是 Docker CE  社区级版本,其中后者是免费的,我将以Docker CE版本进行安装.

首先,我们先查明自己的Linux  distribution 版本是,那个版本的,docker基本支持所有的distribution 系统.

在Linux上安装docker容器

因为我的是Debian 所以此次我将以debian为例,过后我将更新centos的.


系统要求: 安装Docker CE  ,你需要64-bit 版本的 Debian 或者Raspbian.

    

  • Buster 10 (Docker CE 17.11 Edge only)
  • Stretch 9 (stable) / Raspbian Stretch
  • Jessie 8 (LTS) / Raspbian Jessie
  • Wheezy 7.7 (LTS)
同时   Docker  在 x86_64(or amd64) 和 armhf 架构上都支持.

卸载老版本Docker

  如果系统上有先前安装的旧版本,请现将它卸载掉.可能名称叫做 docker   or  docker-engine

$ sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     python-software-properties

$ sudo apt-get remove docker docker-engine docker.io

首次在新主机上安装Docker CE之前,需要设置Docker存储库。之后,您可以从存储库安装和更新Docker。

设置repository (储存库)

1. 更新apt 包索引.

$ sudo apt-get update

2.通过https 安装软件包,来使用储存库.

jessie or newer :

$ sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common

wheezy or older:

$ sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     python-software-properties

我们选择: newer.

3.添加Docker官方GPG**.

curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -

9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88通过搜索指纹的最后8个字符,确认您现在拥有带指纹的** 

$ sudo apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <aaa@qq.com>
sub   4096R/F273FCD8 2017-02-22

这里请移步,这里有详细讲解:http://blog.csdn.net/liguangxianbin/article/details/79460870

使用以下命令设置稳定的存储库。即使您想从边缘测试存储库安装构建,也总是需要稳定的存储 库。要添加边缘或 测试存储库,请在下面的命令中添加单词(或两者)后面的单词edgeteststable

注意:下面的lsb_release -cs子命令返回您的Debian发行版的名称,例如jessie

要添加边缘存储库,请edgestable该命令的最后一行添加

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable"

安装Docker:

1.下载资源包:

转到https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/dists/选择您的Debian版本,浏览到pool/stable/,选择 amd64或者armhf,然后下载.deb您想要安装的Docker CE版本文件。

登录网址:https://download.docker.com/linux/debian/dists/jessie/pool/stable/amd64/ 下载安装包

在Linux上安装docker容器

2.安装Docker CE  ,将下面的路径更改为您下载Docker 软件包的路径.

$ sudo dpkg -i /path/package.deb

在Linux上安装docker容器

3.通过运行hello-world 映像,验证Docker 是否安装.

$ sudo docker run hello-world

第一次运行:

aaa@qq.com:/etc/apt$ sudo docker run hello-world
sudo: unable to resolve host me: Connection timed out
Unable to find image 'hello-world:latest' locally //在本地没有发现'hello-world:latest' 映像
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
Status: Downloaded newer image for hello-world:latest  //下载新的映像从 '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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

再次运行:

aaa@qq.com:/etc/apt$ sudo docker run hello-world
sudo: unable to resolve host me: Connection timed out

Hello from Docker!        //证明成功安装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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/