Docker基本组成

镜像(image):
docker镜像就好比是一个模板,可以通过这个模板创建容器服务,tomcat镜像》run》tomcat01容器(提供服务),通过这个镜像可以创建多个容器,最终项目运行就是在容器中
容器(container):
docker利用容器技术,独立运行一个或者一个组应用,通过镜像来创建
启动,停止,删除,基本命令
目前可以把这个容器理解为一个简易的linux系统
仓库(repository):
仓库是存放镜像的地方
仓库分为公有仓库和私有仓库
Docker Hub(默认为国外)
阿里云等等都有容器服务器(配置镜像加速)
安装Docker
环境准备
-
需要会一点Linux基础
-
ubuntu
-
我们使用XShell远程连接
环境查看
root@iZ8vb1tibpjtksv948jv1kZ:~# pwd
/root
root@iZ8vb1tibpjtksv948jv1kZ:~# uname -r
4.15.0-91-generic
root@iZ8vb1tibpjtksv948jv1kZ:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
安装
帮助文档:https://docs.docker.com/engine/install/ubuntu/
1.卸载旧的版本
sudo apt-get remove docker docker-engine docker.io containerd runc
2.设置存储仓库
·sudo apt-get update
·sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
·curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
·sudo apt-key fingerprint 0EBFCD88
·sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
3.安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
4.查看docker
docker version
5.运行helloworld镜像验证docker engine是否安装正确
sudo docker run hello-world
运行HelloWorld
首先在本地未找到镜像,要到仓库下载

查看镜像:docker images
卸载Docker
卸载依赖
sudo apt-get purge docker-ce docker-ce-cli containerd.io
删除资源
sudo rm -rf /var/lib/docker
Docker的默认工作路径
/var/lib/docker
阿里云镜像加速
-
找到容器镜像服务
-
找到镜像加速器
image.png
-
配置使用
这里用我的镜像地址没用,用自己分配的那一个
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://y94fw0ea.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
网友评论