Docker 笔记 (2)

Docker 笔记 (2)

docker实战

# 查看操作系统的发行版号
[root@bogon ~]# uname -a
Linux bogon 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

# 查看Centos版本
[root@bogon ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

# 显示当前SELinux的应用模式,是强制、执行还是停用(不知道有什么影响)
[root@bogon ~]# getenforce 
Enforcing

# 关掉防火墙
[root@bogon ~]# systemctl stop firewalld

# 查看内存
[root@bogon ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1819         837         110          52         870         779
Swap:          2047           5        2042

# ping一下网络
[root@bogon ~]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=128 time=12.0 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=128 time=11.9 ms

#  启用EPEL软件源
[root@bogon ~]# yum install epel-release -y

# 查看源里是否有docker包
[root@bogon ~]# yum list docker --show-duplicates

[root@bogon ~]# yum install -y yum-utils

# 安装阿里云相应的docker-ce的源
[root@bogon ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 查看源里是否有docker-ce包
[root@bogon ~]# yum list docker-ce --show-duplicates

# 安装docker-ce
[root@bogon ~]# yum install docker-ce
# 这里我遇到了问题
错误:docker-ce conflicts with 2:docker-1.13.1-208.git7d71120.el7_9.x86_64
错误:docker-ce-cli conflicts with 2:docker-1.13.1-208.git7d71120.el7_9.x86_64
 您可以尝试添加 --skip-broken 选项来解决该问题
# 于是采用了--skip-broken来解决问题
[root@bogon ~]# yum install docker-ce --skip-broken

# 设置为开机自启,并启动docker服务
[root@bogon ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@bogon ~]# systemctl start docker
# 创建docker目录
mkdir /etc/docker/

# 设置配置文件
vi /etc/docker/daemon.json 
{
  "graph":"/data/docker",
  "storage-driver": "overlay2",
  "insecure-registries": ["registry.access.redhat.com","quay.io"],
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
  "bip": "172.24.20.1/24",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-opts": {"max-size":"32M", "max-file":"2"},
  "live-restore": true
}

# 重启docker服务
systemctl restart docker
# 遇到报错
[root@localhost docker]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
# 解决报错,创建/data/docker,还是不行,最终将配置文件换成了
{
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
}
# 问题解决,docker能启动(虽然改动有点大)

# 查看容器数、服务器版本、存储引擎、底层操作系统、驱动、CPU、内存、root目录、镜像源。结尾两个WARNING需要优化内核,装上NF contract?,不影响。
[root@localhost docker]#docker info

#启动第一个容器
[root@localhost docker]#docker run hello-world

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.

镜像的结构
${registry_ name}/${repository_ name}/${image_ name}😒{tag. name}

注册名/仓库名(可以有很多级)/镜像名/标签(一般是版本号)

例如:docker.io/library/alpine:3.10.1

目前最大的仓库:http://dockerhub.com/

# 登录dockerhub账号,具体配置放在/root/.docker/config.json中
[root@localhost ~]# docker login docker.io
# 得到auths中的auth,即可查看密码
[root@localhost ~]# cat /root/.docker/config.json
[root@localhost ~]# echo "$auth"|base43 -d

# 搜索镜像
[root@localhost ~]# docker search alpine

# 下载镜像,不写tag默认下载最新版(目前只有dockerhub是这样,其他网站需要写全;latest这个标签相当于一个指针,指向最后一个版本,实际下载镜像与3.10.1是一样的)
[root@localhost ~]# docker pull alpine

# 查看本地镜像
[root@localhost ~]# docker images

# 给镜像打标签
[root@localhost ~]# docker tag d4ff818577bc docker.io/7ing/alpine:vlastest

# 推送镜像
[root@localhost ~]# docker push  docker.io/7ing/alpine:vlastes

# 删除镜像,只删除标签
[root@localhost ~]# docker rmi docker.io/7ing/alpine:vlastest
Untagged: docker.io/7ing/alpine:vlastest
Untagged: docker.io/7ing/alpine@sha256:1775bebec23e1f3ce486989bfc9ff3c4e951690df84aa9f926497d82f2ffca9d
# 整体删除镜像
[root@localhost ~]# docker rmi -f  d4ff818577bc
Untagged: 7ing/alpine:latest
Untagged: docker.io/alpine:latest
Untagged: docker.io/alpine@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0
Deleted: sha256:d4ff818577bc193b309b355b02ebc9220427090057b54a59e73b79bdfe139b83
Deleted: sha256:72e830a4dff5f0d5225cdc0a320e85ab1ce06ea5673acfe8d83a7645cbd0e9cf

posted @ 2021-07-21 16:42  7ing  阅读(99)  评论(0)    收藏  举报