容器内安装curl_史上最全Docker环境安装指南让安装docker简单到爆

本文详细介绍了在Windows 10和老版本Windows、Centos及Ubuntu上安装Docker的步骤,包括手动安装与使用shell脚本自动安装。通过实践操作,确保读者能轻松建立Docker环境,并提供了在线练习Docker的平台。
摘要由CSDN通过智能技术生成

点击上方“Java知音”,选择“置顶公众号”

技术文章第一时间送达!

作者:可优

cnblogs.com/keyou1/p/11511067.html

一、思考❓❔

1.什么是Docker?

303de5c319f67e376cdb4e169eb80c23.png

  • 装应用的容器

  • 开发、测试、运维都偏爱的容器化技术

  • 轻量级

  • 扩展性

  • 一次构建、多次分享、随处运行

2.安装Docker难不难?

166b23aee8d2efab154e308155811a3d.png

So easy!

此文看过之后,读者一定会有一个docker环境

二、Windows上安装Docker??

91d5433ea71766984c53042e86dbd336.png

1.在Windows 10上安装Docker

1.系统需求

31021015fc0a38add51a6313aa040467.png

2.下载安装包

https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe

3.按照安装向导next即可

4.运行

  • 不会自动启动

  • 在开始菜单搜索Docker, 打开即可

ff817a9bd2e3441e0b7f41d0ed8d4167.png

细节配置, 可参考这个链接(https://docs.docker.com/docker-for-windows/#docker-settings-dialog)

5.测试是否安装成功

在CMD中运行如下命令, 有显示版本号或者显示"Hello from Docker!", 则代表安装成功

> docker --version

Docker version 19.03.1

> docker run hello-world
docker : Unable to find image 'hello-world:latest' locally
...

latest:
Pulling from library/hello-world
ca4f61b1923c:
Pulling fs layer
ca4f61b1923c:
Download complete
ca4f61b1923c:
Pull complete
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
Status: Downloaded newer image for hello-world:latest

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

2.在Windows 老版本安装Docker

1.在老版本Windows上安装Docker需要满足如下条件

c71f0a8ea56a0ea271a3c4ab32f9d286.png

下载Docker ToolBox安装包

https://github.com/docker/toolbox/releases/download/v19.03.1/DockerToolbox-19.03.1.exe

2.安装

检测版本:对于Windows 8 或者 8.1, 打开任务管理器 -> 性能 -> 虚拟化已启用

66a8941d1800d80c5e5192f0dca77cc1.png

对于Windows 7可以使用这个工具去检测是否开启虚拟化https://www.microsoft.com/en-us/download/details.aspx?id=592

3.双击exe安装包, 按照安装向导next即可

76efb868b825cd43515744b1976f2c09.png

4.测试是否安装成功

在桌面查找Docker QuickStart图标双击开启Docker

798dc92b1dc769dfdfcdec6610b368bb.png

如果出现User Account Control 提示, 点击是

会出现一个bash终端

运行docker run hello-world, 如果出现"Hello from Docker.", 则代表运行成功。

 $ docker run hello-world
 Unable to find image 'hello-world:latest' locally
 Pulling repository hello-world
 91c95931e552: Download complete
 a8219747be10: Download complete
 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 Engine CLI client contacted the Docker Engine daemon.
  2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.
     (Assuming it was not already locally available.)
  3. The Docker Engine daemon created a new container from that image which runs the
     executable that produces the output you are currently reading.
  4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent it
     to your terminal.

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

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

三、在Linux上安装Docker????

17baa017fb75c99273230070f7808626.png

1.在Centos上安装

1.linux内核版本依赖

kernel version >= 3.8

可以使用如下命令查看

uname -a | awk '{split($3, arr, "-"); print arr[1]}'

2.如果已安装过Docker, 需要移除老版本的Docker

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

3.添加Docker repository yum源

# 国内源, 速度更快, 推荐
sudo yum-config-manager \
    --add-repo \
    https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo


# 官方源, 服务器在国外, 安装速度慢
# $ sudo yum-config-manager \
#     --add-repo \
#     https://download.docker.com/linux/centos/docker-ce.repo

4.开始安装Docker Engine

sudo yum makecache fast
sudo yum install docker-ce docker-ce-cli containerd.io

5.开启Docker

sudo systemctl enable docker
sudo systemctl start docker

6.验证是否安装成功

 sudo docker run hello-world

如果出现"Hello from Docker.", 则代表运行成功

7.如果在每次运行docker命令时, 在前面不添加sudo, 可以执行如下命令:

sudo usermod -aG docker $USER

8.如果嫌上面安装步骤麻烦, 可以运行如下脚本来安装

注意:不能在生产系统中使用

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun

sudo systemctl enable docker
sudo systemctl start docker

sudo groupadd docker
sudo usermod -aG docker $USER

2.在Ubuntu上安装

1.linux内核版本依赖

kernel version >= 3.8

可以使用如下命令查看

uname -a | awk '{split($3, arr, "-"); print arr[1]}'

操作系统依赖, 如下版本都可以

Disco 19.04
Cosmic 18.10
Bionic 18.04 (LTS)
Xenial 16.04 (LTS)

2.如果已安装过Docker, 需要移除老版本的Docker

sudo apt-get remove docker docker-engine docker.io containerd runc

3.使用Docker repository 来安装

# 更新apt包索引
sudo apt-get update

# 为支持https
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# 添加Docker GPG秘钥
# 国内源
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 或者国外源
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加安装源
# 推荐国内源
sudo add-apt-repository \
    "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
# 或者国外源
# sudo add-apt-repository \
#   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
#   $(lsb_release -cs) \
#   stable"

4.安装Docker

# 更新apt包索引
sudo apt-get update

# 安装docker
sudo apt-get install docker-ce docker-ce-cli containerd.io

5.开启Docker

sudo systemctl enable docker
sudo systemctl start docker

6.验证是否安装成功

 sudo docker run hello-world

如果出现"Hello from Docker.", 则代表运行成功

7.如果在每次运行docker命令时, 在前面不添加sudo, 可以执行如下命令:

sudo usermod -aG docker $USER

四、使用shell脚本安装Docker??

1.在Ubuntu和Centos上安装

install_docker_.sh

#!/bin/bash
#Author: 柠檬班可优
#Date: 2019-06-06
#install docker in ubuntu and centos


function install_docker_in_ubuntu
{
    sudo  apt-get update -y
    # install some tools
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg-agent \
        software-properties-common \
        net-tools \
        wget -y

    # install docker
    curl -fsSL get.docker.com -o get-docker.sh
    sh get-docker.sh

    # start docker service
    sudo groupadd docker &> /dev/null
    sudo gpasswd -a "${USER}" docker
    sudo systemctl start docker

    rm -rf get-docker.sh
}


function install_docker_in_centos
{
    # install some tools
    sudo yum install -y git vim gcc glibc-static telnet bridge-utils

    # install docker
    curl -fsSL get.docker.com -o get-docker.sh
    sh get-docker.sh

    # start docker service
    sudo groupadd docker &> /dev/null
    sudo gpasswd -a "${USER}" docker
    sudo systemctl start docker

    rm -rf get-docker.sh

}


SYSTEM_NAME="$(awk -F= '/^NAME/{print $2}' /etc/os-release)"
if [[ "${SYSTEM_NAME,,}" =~ "ubuntu"  ]] ; then
    echo "Your system is ubuntu."
    echo "Installing Docker in ubuntu..."
    install_docker_in_ubuntu
elif [[ "${SYSTEM_NAME,,}" =~ "centos" ]] ; then
    echo "Your system is centos."
    echo "Installing Docker in centos..."
    install_docker_in_centos
else
    echo "This script can only run in ubuntu and centos system."
    exit 1
fi

2.运行脚本

bash install_docker_.sh

五、在线练习docker??

katacoda网站:

https://www.katacoda.com/
每10分钟一个小练习

Play with Docker网站:

https://labs.play-with-docker.com/
注册docker账号并登陆
每次能使用4个小时,之后会被清空

六、总结??

本文介绍了安装docker的多种方式,相信总有一种适合你的

学习热门的Docker容器化技术,安装docker是第一步

推荐阅读(点击即可跳转阅读)

1.SpringBoot内容聚合

2.面试题内容聚合

3.设计模式内容聚合

4.Mybatis内容聚合

5.多线程内容聚合

觉得不错?欢迎转发分享给更多人

43424b1f28e3778add6d7683b6dba492.png

我知道你 “在看6b93c9221045e7fa39561c0793bceb57.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值