Docker第一天作业

一、安装docker-ce
说明:我用的版本为Centos7.9

1.写docker-ce源

[root@localhost yum.repos.d]# cat aliyun.repo 
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/
gpgcheck=0

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/extras/x86_64/
gpgcheck=0

[root@localhost yum.repos.d]# cat docker-ce.repo
[docker-ce]
name=docker-ce
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7.9/x86_64/stable/
gpgcheck=0

2.更新源

[root@localhost ~]# yum makecache fast

请添加图片描述

3.安装docker-ce
默认安装docker-ce是最新版本

[root@localhost ~]# yum -y install docker-ce 

请添加图片描述

centos7.9版本没有出现报错
若使用其他版本出现如下报错:

Error: Package: 3:docker-ce-19.03.8-3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: containerd.io-1.2.13-3.1.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: 3:docker-ce-19.03.8-3.el7.x86_64 (docker-ce-stable)
Requires: libseccomp >= 2.3
Available: libseccomp-2.2.1-1.el7.i686 (bae)
libseccomp = 2.2.1-1.el

则需要安装container-selinux,下载网络yum源,再安装docker-ce即可

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install docker-ce

[root@localhost yum.repos.d]# rpm -q docker-ce
docker-ce-19.03.11-3.el7.x86_64
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker

4、启动docker
配置docker镜像加速

[root@localhost ~]# vim /etc/docker/daemon.json
{
	"registry-mirrors":["https://registry.docker-cn.com"]
}
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker info

启动服务
① 重载docker启动配置

[root@localhost~]# systemctl daemon-reload

②启动docker服务

[root@localhost~]# systemctl start docker

③查看docker版本

[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:05:12 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:03:33 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.7
  GitCommit:        0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb
 runc:
  Version:          1.1.3
  GitCommit:        v1.1.3-0-g6724737
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

[root@localhost ~]# docker --version
Docker version 20.10.17, build 100c701

二、下载并查看镜像
nginx

root@localhost ~]# docker pull nginx:1.14-alpine
1.14-alpine: Pulling from library/nginx
bdf0201b3a05: Pull complete
3d0a573c81ed: Pull complete
8129faeb2eb6: Pull complete
3dc99f571daf: Pull complete
Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status: Downloaded newer image for nginx:1.14-alpine

[root@localhost ~]# docker images
REPOSITORY   TAG           IMAGE ID       CREATED       SIZE
nginx        1.14-alpine   8a2fb25a19f5   3 years ago   16MB

apline

[root@localhost ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
213ec9aee27d: Pull complete 
Digest: sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
[root@localhost ~]# docker images
REPOSITORY   TAG           IMAGE ID       CREATED       SIZE
alpine       latest        9c6f07244728   6 days ago    5.54MB
nginx        1.14-alpine   8a2fb25a19f5   3 years ago   16MB

拉取httpd的镜像并且给httpd镜像重新打标签为 test/httpd:v1

[root@localhost ~]# docker pull  httpd
Using default tag: latest
latest: Pulling from library/httpd
1efc276f4ff9: Pull complete 
aed046121ed8: Pull complete 
4340e7be3d7f: Pull complete 
80e368ef21fc: Pull complete 
80cb79a80bbe: Pull complete 
Digest: sha256:343452ec820a5d59eb3ab9aaa6201d193f91c3354f8c4f29705796d9353d4cc6
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest

[root@localhost ~]# docker tag httpd test/httpd:v1  #打标签
[root@localhost ~]# docker images
REPOSITORY   TAG           IMAGE ID       CREATED       SIZE
alpine       latest        9c6f07244728   6 days ago    5.54MB
test/httpd   v1            f2a976f932ec   2 weeks ago   145MB
httpd        latest        f2a976f932ec   2 weeks ago   145MB
nginx        1.14-alpine   8a2fb25a19f5   3 years ago   16MB

二、启动容器docker run
docker run hello-world

[root@localhost ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

[root@localhost ~]# docker run hello-world
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/

docker run -it ubuntu bash

[root@localhost ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
d19f32bd9e41: Pull complete 
Digest: sha256:34fea4f31bf187bc915536831fd0afc9d214755bf700b5cdb1336c82516d154e
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[root@localhost ~]#  docker run -it ubuntu bash
root@6408611b9d29:/# ls
bin   dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
boot  etc  lib   lib64  media   opt  root  sbin  sys  usr
root@6408611b9d29:/# exit
exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值