So easy!
此文看过之后,读者一定会有一个docker环境
1.系统需求
2.下载安装包
https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe
3.按照安装向导next即可
4.运行
细节配置, 可参考这个链接(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.
...
1.在老版本Windows上安装Docker需要满足如下条件
下载Docker ToolBox安装包
https://github.com/docker/toolbox/releases/download/v19.03.1/DockerToolbox-19.03.1.exe
2.安装
检测版本:对于Windows 8 或者 8.1, 打开任务管理器 -> 性能 -> 虚拟化已启用
对于Windows 7可以使用这个工具去检测是否开启虚拟化https://www.microsoft.com/en-us/download/details.aspx?id=592
3.双击exe安装包, 按照安装向导next即可
4.测试是否安装成功
在桌面查找Docker QuickStart图标双击开启Docker
如果出现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/
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
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
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
bash install_docker_.sh
katacoda网站:
https://www.katacoda.com/
每10分钟一个小练习
Play with Docker网站:
https://labs.play-with-docker.com/
注册docker账号并登陆
每次能使用4个小时,之后会被清空
本文介绍了安装docker的多种方式,相信总有一种适合你的
学习热门的Docker容器化技术,安装docker是第一步
如果您发现该资源为电子书等存在侵权的资源或对该资源描述不正确等,可点击“私信”按钮向作者进行反馈;如作者无回复可进行平台仲裁,我们会在第一时间进行处理!
加入交流群
请使用微信扫一扫!