搭建Docker

Docker简介

Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。
让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
Docker官网地址
Docker操作手册地址
`

前期准备

因为Docker需要Centos内核版本高于3.10,所以需要通过rename-r命令去查看系统内核和系统版本(注意Centos7满足3.10,但安装Docker需要64位的系统否则安装不了):
Centos i386 和 i686都是32位的,X86则是64位的。

[root@localhost ye]#uanme
3.10.0-1160.el7.x86_64
  1. 使用 root 权限登录 Centos。确保 yum 包更新到最新。
sudo yum -y update
  1. 首先查看是否已经安装了Docker,无安装则无显示,有安装则有显示
rpm -qa|grep docker

卸载docker

sudo yum remove -y docker*
  1. 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils

设置yum的源

,国内建议设置阿里源。最后更新包的索引

  1. docker默认的源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  1. 阿里云的源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
  1. 可以查看Docker仓库里面的所有版本,并且选择特定进行安装,也可以使用默任最新。

查看所有版本

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

直接安装

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

启动docker

启动docker前,一定要关闭防火墙后!!
永久关闭防火墙

systemctl disabled firewalld

暂时关闭防火墙

systemctl stop firewalld

启动docker

systemctl  start  docker

查看docker状态

[root@localhost ye]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-07-23 07:35:56 PDT; 1min 17s ago
     Docs: https://docs.docker.com
 Main PID: 60281 (dockerd)
    Tasks: 9
   Memory: 105.3M
   CGroup: /system.slice/docker.service
           └─60281 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/con...

Jul 23 07:35:54 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:54 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:54 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:54 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:55 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:56 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:56 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:56 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Jul 23 07:35:56 localhost.localdomain systemd[1]: Started Docker Application ...
Jul 23 07:35:56 localhost.localdomain dockerd[60281]: time="2022-07-23T07:35:...
Hint: Some lines were ellipsized, use -l to show in full.

使用hello world的镜像查看docker

docker run hello-world

结果

[root@localhost ye]# docker run hello world
Unable to find image 'hello:latest' locally
docker: Error response from daemon: pull access denied for hello, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
[root@localhost ye]# docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:53f1bbee2f52c39e41682ee1d388285290c5c8a76cc92b42687eecf38e0af3f0
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/

32位安装失败的提示为HTTP 404
在安装docker时failure: repodata/repomd.xml from mirrors.aliyun.com_dockece_linux_centos_docker-ce.repor

请跳转该文章。报错404且无法安装docker报错


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值