2021-09-27

任务一 安装Docker

1.1 docker简介

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。
容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)。几乎没有性能开销,可以很容易地在机器和数据中心中运行。最重要的是,他们不依赖于任何语言、框架或包括系统。
1.2 为什么要使用docker
作为一种新兴的虚拟化方式,Docker 跟传统的虚拟化方式相比具有众多的优势。
首先,Docker 容器的启动可以在秒级实现,这相比传统的虚拟机方式要快得多。 其次,Docker 对系统资源的利用率很高,一台主机上可以同时运行数千个 Docker 容器。
容器除了运行其中应用外,基本不消耗额外的系统资源,使得应用的性能很高,同时系统的开销尽量小。传统虚拟机方式运行 10 个不同的应用就要起 10 个虚拟机,而Docker 只需要启动 10 个隔离的应用即可。
Docker主要解决的问题:
保证程序运行环境的一致性;
降低配置开发环境、生产环境的复杂度及成本;
实现程序的快速部署和分发。

1.3 Docker安装

环境准备

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
getenforce 0
 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

安装Docker

yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息

.yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新并安装 Docker-CE。

yum makecache fast
yum -y install docker-ce

开启docker服务

[root@docker ~]# systemctl daemon-reload (重新加载)
[root@docker ~]# systemctl restart docker
[root@docker ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

任务二 Docker镜像管理/仓库管理

2.1 什么是镜像
简单说, Docker镜像是一个不包含Linux内核而又精简的Linux操作系统。
2.2 镜像从哪里来
Docker Hub是由Docker公司负责维护的公共注册中心,包含大量的容器镜像, Docker工具默认从这个公共镜像库下载镜像。
https://hub.docker.com/explore
默认是国外的源,下载会慢,可以国内的源提供下载速度:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://04be47cf.m.daocloud.io
2.3 镜像的基本操作
选项 描述
ls 列出镜像
build 构建镜像来自Dockerfile
history 查看镜像历史
inspect 显示一个或多个镜像详细信息
pull 发布容器端口到主机
push 推送一个镜像到镜像仓库
prune 移除未使用的镜像。没有被标记或被任何容器引用的。
export 将文件系统作为一个tar归档文件导出到STDOUT
import 从归档文件中创建镜像
tag 连接容器到一个网络
load 将镜像存储文件导入到本地镜像库
-v 绑定挂载一个卷
–restart 容器退出时重启策略,默认no

2.4 注册仓库DockerHub

https://hub.docker.com/ 注册账号,登录邮箱激活

2021-09-27_第1张图片
2021-09-27_第2张图片

2021-09-27_第3张图片

2021-09-27_第4张图片

# docker login docker.io
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 账号
Password: 密码
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

2.5 搜索镜像

搜索alpine、nginx镜像

[root@bogon ~]# docker search alpine
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
alpine                                 A minimal Docker image based on Alpine Linux…   7905      [OK]       
mhart/alpine-node                      Minimal Node.js built on Alpine Linux           483                  

2.6 下载镜像

下载alpine镜像

[root@bogon ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
a0d0a0d46f8b: Pull complete 

下载nginx镜像

[root@bogon ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx

a330b6cecb98: Pull complete 
e0ad2c0621bc: Pull complete 
9e56c3e0e6b7: Pull complete 
09f31c94adc6: Pull complete 
32b26e9cdb83: Pull complete 
20ab512bbb07: Pull complete 

下载指定tag

[root@bogon ~]# docker pull alpine:3.12.3
3.12.3: Pulling from library/alpine
801bfaa63ef2: Pull complete 
Digest: sha256:3c7497bf0c7af93428242d6176e8f7905f2201d8fc5861f45be7a346b5f23436
Status: Downloaded newer image for alpine:3.12.3
docker.io/library/alpine:3.12.3

2.7 查看本地镜像

[root@bogon ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    ad4c705f24d3   2 weeks ago    133MB
alpine       latest    14119a10abf4   4 weeks ago    5.59MB
alpine       3.12.3    389fef711851   9 months ago   5.57M’``

后续内容将持续更新有用的点个赞支持一波

你可能感兴趣的:(linux,docker,linux,运维)