Docker(一)安装和卸载

目录

一、环境准备

二、安装Docker

1、卸载旧的版本(如果安装过)

2、安装需要的安装包

3、设置镜像的仓库(官方默认是国外的,推荐使用国内阿里云镜像)

4、安装docker相关的内容

5、启动docker

6、测试hello world

7、查看下载的这个hello-world镜像

三、卸载Docker

1.卸载依赖

2.删除资源

四、Run流程和Docker原理

五、安装Docker可视化界面工具

1、Protainer(临时使用,不推荐)

1、安装准备(选择安装社区版)

2、设置卷

3、拉取最新镜像

4、创建并启动容器


一、环境准备

centOS 7

环境查看

查看系统内核:系统内核需要 3.10 以上的(必须)

uname -r

 查看系统版本 

cat /etc/os-release

二、安装Docker

官方帮助文档:Install Docker Engine on CentOS | Docker Documentation

1、卸载旧的版本(如果安装过)

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

2、安装需要的安装包

yum install -y yum-utils

3、设置镜像的仓库(官方默认是国外的,推荐使用国内阿里云镜像)

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

4、安装docker相关的内容

#更新软件包索引

yum makecache fast

#安装docker软件包   docker-ce社区版   ee 企业版

yum install docker-ce docker-ce-cli containred.io

5、启动docker

#启动

systemctl start docker

#查看docker是否安装成功和版本

docker version

6、测试hello world

docker run hello-world

#####
Unable to find image 'hello-world:latest' locally       #没有找到hello-world镜像
latest: Pulling from library/hello-world        #远程拉取官方镜像
2db29710123e: Pull complete                 #获取签名信息拉取成功
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
#####
安装成功正常运行

7、查看下载的这个hello-world镜像

#查看镜像

docker images

三、卸载Docker

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

1.卸载依赖

yum remove docker-ce docker-ce-cli containerd.io

2.删除资源

# /var/lib/docker 默认工作路径(资源路径)

rm -rf /var/lib/docker


阿里云镜像加速
sudo mkdir -p /etc/docker        #编写配置文件

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://263xr7xg.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload        #从启docker
sudo systemctl restart docker        #启动docker

四、Run流程和Docker原理

五、安装Docker可视化界面工具

1、Protainer(临时使用,不推荐)

Docker图形化界面管理工具!

Portainer是一个轻量级的容器管理平台,主要用于简化Docker环境的部署和管理。用户可以通过图形界面直观地管理容器、镜像、卷和网络等Docker资源,支持Docker引擎和Swarm模式。Portainer的主要作用包括容器管理、镜像管理、团队与权限管理,以及提供API接口实现自动化部署和监控,使Docker资源管理更加高效和便捷。

1、安装准备(选择安装社区版

官网:Kubernetes and Docker Container Management Software (portainer.io)

2、设置卷

首先,创建Portainer Server将用于存储其数据库的卷

创建Docker卷portainer_data

docker volume create portainer_data

3、拉取最新镜像

docker pull portainer/portainer-ce:latest

4、创建并启动容器

docker run -d --name portainer -p 8088:9000 -p 8000:8000 -p 9443:9443 --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

-p: 指定宿主机端口和容器端口:

默认情况下,Portainer生成并使用自签名SSL证书来保护端口9443。另外,您也可以在安装期间或安装完成后通过Portainer UI提供自己的SSL证书。
如果由于遗留原因需要打开HTTP端口9000,请在docker run命令中添加以下命令:

- p 9000:9000

我这里将自定义8088端口映射到9000端口,外部访问直接请求端口号为8088

--restart=always: 代表在容器退出时总是重启容器,还有其他几种重启策略:no、on-failure、on-failuer:n、unless-stopped

- v: 目录映射,将/var/run/docker.sock映射到容器中,用于访问Docker的守护进程,控制Docker。portainer_data:/data将数据映射到容器卷。

访问测试:http://{ip}:8088/

首次登录需要创建用户密码

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值