最近一年在工作上经常使用Docker与K8S,除了利用其打镜像,部署服务外,还基于Docker与K8S开发了一套CICD流水线平台,为了加深相关知识点的理解,所以从今天开始会定期更新学习笔记,本套学习笔记前半部分会讲述Docker的使用,后半部分则是K8S的使用,过程中有任何错误之处还望各位大佬指正哈。
所谓工欲善其事,必先利其器,我们首先来学习下Docker的安装过程。
PS:我这边安装了Ubuntu 18.04 server版虚拟机,然后在虚拟机中安装Docker。
Docker有三种安装方式:
使用Docker仓库安装;
使用官方安装脚本安装;
使用软件包安装。
官方推荐的是通过Docker仓库安装,通过此方式后期可以方便我们更新Docker。所以我们也使用此方式进行安装。
1、更新apt包索引
sudo apt-get update
2、安装必要的软件包
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
3、添加Docker官方GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
4、设置稳定版仓库
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5、安装最新版Docker引擎
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
6、验证是否安装OK
sudo docker run hello-world
此命令将会从docker仓库中拉取hello-world镜像,执行后输出如下:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Already exists
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
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/