栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Docker概述

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker概述

Docker概述

安装教程:https://www.runoob.com/docker/ubuntu-docker-install.html
官方教程:https://docs.docker.com/engine/install/ubuntu/
本文记录本人安装docker的相关流程笔记(ubuntu)

一、 docker安装

卸载并删除原有docker

sudo apt-get remove docker docker-engine docker.io containerd runc
rm -rf var/lib/docker

安装相关依赖包:

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common gnupg  lsb-release

官方下载gpg

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  echo 
  "deb [arch=$(dpkg --print-architecture) 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

其他方式安装gpg密钥(选一个安装就行):

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -//中科大的
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - //阿里云的
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - //官方的

​展示 Docker 的官方 GPG 密钥:

sudo apt-key fingerprint 0EBFCD88

展示aptkey

sudo apt-key list

​ 删除apt-key

aptkey apt-key del 0EBFCD88

添加Docker远程仓库

sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

(1) 安装最新版本的 Docker Engine-Community 和 containerd
(安装核心、客户端、docker 容器 一般用ce,docker-ee 是企业授权版本的 一般不用)

sudo apt-get install docker-ce docker-ce-cli containerd.io  

(2) 安装最新版本的 Docker Engine-Community 和 containerd

​ 查看各个版本 Docker:

  apt-cache madison docker-ce

选择一个版本进行安装

sudo apt-get install docker-ce=5:20.10.9~3-0~ubuntu-focal docker-ce-cli=5:20.10.9~3-0~ubuntu-focal containerd.io

docker 安装完毕了!!

二、 启动docker服务器端
sudo service docker start
systemctl start docker

查看docker 版本

docker version

启动测试:docker hello world

sudo docker run hello-world

docker的运行流程:

1、从本地寻找hello-world镜像
2、没有的话就从远程仓库pull到本地
3、之后就运行了

三、使用阿里加速器:

阿里云网址:https://cr.console.aliyun.com/,自己在阿里云申请账号,并找到镜像加速器(免费的,超赞!),后面针对不同的环境配置。

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://XXXXXXX.mirror.aliyuncs.com"] //换成自己的仓库地址
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二、docker概念

虚拟机和docker

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZqwttgAh-1635860472051)(C:UsersAdministratorAppDataRoamingTyporatypora-user-imagesimage-20211101211615501.png)]

Docker 概述
Docker 安装
Docker 命令
镜像命令
容器命令
操作命令
Docker镜像
容器数据卷
DOckerFile
DOcker 网络原理
IDEA整合Docker
DOcker COmpose 集群
DOcker Swarm 集群
CICD jenkins
四、docker基本命令

查看版本

docker version	

查看明细信息

docker info 	

docker显示的明细信息

五、镜像命令

查看镜像 sudo docker images

dangs@dangs-YangTianM4000e-17:/etc/docker$ sudo docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   5 weeks ago   13.3kB
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE_ID 镜像的ID
CREATE镜像的创建时间
SIZE 镜像的大小

-a --all	列出所有的镜像
-q --quiet 	显示镜像的idxxxxxxxxxx

搜索镜像

docker search mysql --filter=STARS=3000  //可以找到3000star以上的

拉取镜像 以mysql为例

docker pull mysql
dangs@dangs-YangTianM4000e-17:/etc/docker$ sudo docker pull mysql  (:5.7 加上这个就不是最新版本了)  联合文件系统
Using default tag: latest 后面不加tag就默认的是最新版本
latest: Pulling from library/mysql
b380bbd43752: Pull complete  //分段下载
f23cbf2ecc5d: Pull complete 
30cfc6c29c0a: Pull complete 
b38609286cbe: Pull complete 
8211d9e66cd6: Pull complete 
2313f9eeca4a: Pull complete 
7eb487d00da0: Pull complete 
4d7421c8152e: Pull complete 
77f3d8811a28: Pull complete 
cce755338cba: Pull complete 
69b753046b9f: Pull complete 
b2e64b0ab53c: Pull complete 
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest 最新的docker

//两者等价
docker pull mysql
docker pull docker.io/library/mysql:latest

如果下载5.7 有一部分已经存在了
dangs@dangs-YangTianM4000e-17:/etc/docker$ sudo docker pull mysql:5.7
5.7: Pulling from library/mysql
b380bbd43752: Already exists 
f23cbf2ecc5d: Already exists 
30cfc6c29c0a: Already exists 
b38609286cbe: Already exists 
8211d9e66cd6: Already exists 
2313f9eeca4a: Already exists 
7eb487d00da0: Already exists 
a71aacf913e7: Pull complete 
393153c555df: Pull complete 
06628e2290d7: Pull complete 
ff2ab8dac9ac: Pull complete 
Digest: sha256:2db8bfd2656b51ded5d938abcded8d32ec6181a9eae8dfc7ddf87a656ef97e97
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

删除镜像

docker rmi -f  [容器id] 删除镜像
docker rmi -f $ (docker images -aq) 删除全部的镜像
容器命令

说明:我们有了镜像才可以创建容器,linux

sudo docker pull ubuntu  //套娃ubuntu
sudo docker run -it ubuntu /bin/bash

docker启动命令

docker run [可选] image
#参数说明
--name="Name" 容器名字 tomcat01 tomcat02 区分容器
-d  后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p  指定容器的端口 -p 8080:8080
	-p 主机端口:容器端口(常用)
	-p ip:主机端口:容器端口
	-p 容器端口
	容器端口
-P 随机指定端口

退出docker

exit

展示当前运行的docker

docker ps -a  
-a 附带历史运行的docker
-n=1 只显示一个docker记录
dangs@dangs-YangTianM4000e-17:/var/cache$ sudo docker ps -a
ConTAINER ID   IMAGE         COMMAND       CREATED         STATUS                       PORTS     NAMES
2fe47605af02   ubuntu        "/bin/bash"   3 minutes ago   Exited (127) 8 seconds ago             bold_lamport
c13a5b86d692   hello-world   "/hello"      27 hours ago    Exited (0) 27 hours ago                modest_elion
f9cc958dee9a   hello-world   "/hello"      7 days ago      Exited (0) 7 days ago                  interesting_elbakyan
3b502643b938   hello-world   "/hello"      7 days ago      Exited (0) 7 days ago                  vigorous_hugle
2a5bdc5e6e2d   hello-world   "/hello"      7 days ago      Exited (0) 7 days ago                  affectionate_neumann
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/395577.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号