首页 > 其他分享 >docker学习笔记1(在线安装及离线安装)

docker学习笔记1(在线安装及离线安装)

时间:2023-03-03 11:33:30浏览次数:49  
标签:x86 安装 离线 ce 64 docker rpm el7

Centos7安装docker引擎

官方安装文档
https://docs.docker.com/engine/install/centos/#install-using-the-repository
Docker分两个大版本,一个是CE,一个是EE。
CE为社区版,免费,支持周期为7个月。
EE为企业编,付费,支持周围为24个月。
这边以docker CE版的安装为例。

1.卸载

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

卸载时,镜像、容器、卷、网络都不会自动删除。(/var/lib/docker/)

2.安装方式很多种,有用在线仓库安装,有用离线包安装,我这边结合两种:

2.1使用在线仓库安装

安装yum-utils工具(包含yum-config-manager工具)

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

添加repo

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo


官方的repo包下不来,考虑国内镜像(例如阿里镜像源、清华源、163等)
清华源镜像参考:https://mirror.tuna.tsinghua.edu.cn/help/docker-ce/
阿里云镜像参考:https://developer.aliyun.com/mirror/docker-ce

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

sudo yum makecache fast


默认安装最新的版本:

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

当然你也可以指定版本

yum list docker-ce --showduplicates | sort -r

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin

趁机捞下包( docker-ce 23.0.1):

sudo mkdir docker-ce-centos7-offline-installer
cd docker-ce-centos7-offline-installer
sudo yum install --downloadonly --downloaddir=./ docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
[root@demo01 docker-ce-centos7-offline-installer]# ls
audit-2.8.5-4.el7.x86_64.rpm
audit-libs-2.8.5-4.el7.x86_64.rpm
audit-libs-python-2.8.5-4.el7.x86_64.rpm
checkpolicy-2.5-8.el7.x86_64.rpm
containerd.io-1.6.18-3.1.el7.x86_64.rpm
container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
docker-buildx-plugin-0.10.2-1.el7.x86_64.rpm
docker-ce-23.0.1-1.el7.x86_64.rpm
docker-ce-cli-23.0.1-1.el7.x86_64.rpm
docker-ce-rootless-extras-23.0.1-1.el7.x86_64.rpm
docker-compose-plugin-2.16.0-1.el7.x86_64.rpm
docker-scan-plugin-0.23.0-3.el7.x86_64.rpm
fuse3-libs-3.6.1-4.el7.x86_64.rpm
fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
libcgroup-0.41-21.el7.x86_64.rpm
libsemanage-python-2.5-14.el7.x86_64.rpm
policycoreutils-2.5-34.el7.x86_64.rpm
policycoreutils-python-2.5-34.el7.x86_64.rpm
python-IPy-0.75-6.el7.noarch.rpm
setools-libs-3.3.8-4.el7.x86_64.rpm
slirp4netns-0.4.3-4.el7_8.x86_64.rpm

2.2使用离线包安装

sudo yum install *.rpm -y


服务启动并加入开机自启动

systemctl enable docker.service docker.socket containerd.service

systemctl start docker.service docker.socket containerd.service
systemctl status docker.service docker.socket containerd.service


初学者肯定要来个hello world,以下解释的是,为了打印出hello world,docker做了哪些事情(过程)。

[root@demo01 docker-ce-centos7-offline-installer]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:6e8b6f026e0b9c419ea0fd02d3905dd0952ad1feea67543f525c73a0a790fefb
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/

版本信息:
[root@demo01 docker-ce-centos7-offline-installer]# docker version
Client: Docker Engine - Community
 Version:           23.0.1
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        a5ee5b1
 Built:             Thu Feb  9 19:51:00 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.1
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       bc3805a
  Built:            Thu Feb  9 19:48:42 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
组件版本:
[root@demo01 docker-ce-centos7-offline-installer]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.16.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 23.0.1
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-957.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.934GiB
 Name: demo01
 ID: d0487dac-199e-4557-ac1b-63ae44d156a4
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

删除docker

删除安装包:
yum remove docker-ce
删除镜像、容器、配置文件等内容:
rm -rf /var/lib/docker

docker常用命令

搜索仓库镜像:docker search 镜像名
拉取镜像:docker pull 镜像名
查看正在运行的容器:docker ps
查看所有容器:docker ps -a
删除容器:docker rm container_id
查看镜像:docker images
删除镜像:docker rmi image_id
启动(停止的)容器:docker start 容器ID
停止容器:docker stop 容器ID
重启容器:docker restart 容器ID
启动(新)容器:docker run -it ubuntu /bin/bash
进入容器:docker attach 容器ID或docker exec -it 容器ID /bin/bash,推荐使用后者。
更多命令docker help

标签:x86,安装,离线,ce,64,docker,rpm,el7
From: https://www.cnblogs.com/haiyoyo/p/17174959.html

相关文章

  • kali linux安装配置
    目录   虚拟机VMware安装配置   安装kalilinuxOS   安装vmtools   配置kali实验环境       1.更改默认root密码       2.设置中文(看个......
  • 基于docker镜像快速搭建开发环境
    准备工作本地docker环境,服务docker镜像下载地址:https://registry-d.ym/harbor/projects/22/repositories哪吒的环境变量配置和挂载配置:http://nezha.compass.ym/#/appM......
  • CTEX套装的安装与使用
    目录1.前言2.安装前的准备3.CTEX套装的下载及安装4.编辑器WinEdt的设置5.编译.tex文件6.Latex的学习和使用6.1如何学习使用Latex6.2一些提示1.前言完整的LaTeX......
  • docker记录
    安装(Ubuntu)1.更新aptapt-getupdate2.安装相关依赖apt-getinstallapt-transport-httpsca-certificatescurlgnupg-agen3.添加docker的官方密钥curl-fsSLhttp......
  • MySQL安装
    MySQL安装SQLSQL语言是一种对数据库、数据进行操作、管理、查询的工具MySQL安装官网下载将MySQLServer(版本)\bin的地址配置到系统变量->Path中cmd登陆测试:MyS......
  • npm vue-router安装报错
    因为2022年2月7日以后,vue-router的默认版本,为4版本,而且vue-router4,只能在vue3中,只有vue-router3中,能用在vue2中如果把vue-router4强制安装到vue2中,则会报上面的错误;解......
  • PHP8安装(centos7环境)
    一、事先安装的模块yuminstall-ybzip2-devellibcurl-devellibxml2-develsqlite-develonigurumaoniguruma-devellibxml2libxml2-develbzip2bzip2-devellibcurl......
  • 轻量级CI/CD发布部署环境搭建及使用_05_安装宿主机环境(jdk、nodejs、maven、python2)
    轻量级CI/CD发布部署环境搭建及使用_05_安装宿主机环境(jdk、nodejs、maven、python2)尽自己的绵薄之力,为开源技术分享添砖加瓦本篇幅较多,请按步骤实验安装,截图中涉及的......
  • Docker环境下安装Redis 集群
    Redis三种解决方案哈希取余分区   优点:简单粗暴,直接有效缺点:不好扩缩容,某个节点宕机,会导致hash取余全部数据重新洗牌一致性哈希环优点:加入或......
  • Sentinel安装&配置使用&规则持久化
    目录Sentinel是什么安装部署1.下载2.运行3.访问项目连接Sentinel新建一个项目POMYML启动类Controller启动项目Sentinel规则配置流控规则a.直接-快速失败b.关联-快速失败c.......