美文网首页
Centos下的纯命令记录Docker学习(1)-安装

Centos下的纯命令记录Docker学习(1)-安装

作者: 小钟钟同学 | 来源:发表于2020-10-19 14:36 被阅读0次

docker架构图:

image.png

抄录自菜鸟:

Docker 包括三个基本概念:

  • 镜像(Image):Docker 镜像(Image),就相当于是一个 root 文件系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统的 root 文件系统。
  • 容器(Container):镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的类和实例一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
  • 仓库(Repository):仓库可看成一个代码控制中心,用来保存镜像。

Docker 使用客户端-服务器 (C/S) 架构模式,使用远程API来管理和创建Docker容器。

Docker 容器通过 Docker 镜像来创建。

容器与镜像的关系类似于面向对象编程中的对象与类。

补充说明:

docker build :镜像构建
docker pull : 镜像拉取
docker run: 镜像启动

关于环境搭建,实验性的话可以推荐在线的
实验性的话可以推荐在线的方式1:
https://labs.play-with-docker.com/
注册账号登入
第二种如果是再winddos下的话 可以的话直接安装这个也可以!
可以参考:
DockerToolbox安装docker - Windows 10
https://www.jianshu.com/p/2aa5b05717c6

环境

image.png

前提

Docker要求的系统内核高于3.10,查看系统版本信息

[root@localhost ~]# uname -r
3.10.0-514.el7.x86_64
[root@localhost ~]#

准备 更新的相关的yum包

[root@localhost ~]# yum update

更换设置YUM源设置:

[root@localhost ~]#yum-config-manager -add-repo
https://download.docker.com/linux/centos/docker-ce.repo

更换为阿里云:

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装

使用官方脚本的安装:

[root@localhost ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

提示错误:

# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
Error: Unable to curl repository file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo, is it valid?

尝试解决:
1):删除旧版的数据(没安装过)

[root@localhost ~]#  yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-selinux \
>                   docker-engine-selinux \
>                   docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal

2)第2步: 安装相关的依赖

[root@localhost ~]# yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

3): 配置YUN源:

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

补充:查看docker版本

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

再次尝试的安装还是依然报错

[root@localhost ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
Error: Unable to curl repository file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo, is it valid?
[root@localhost ~]#

然后再使用yum进行其他安装包的安装依然报错的提示是:



[root@localhost ~]# yum clean metadata
Loaded plugins: fastestmirror
Cleaning repos: base docker-ce-stable epel extras updates
1 metadata file removed
0 sqlite files removed
0 metadata files removed
[root@localhost ~]# yum update
Loaded plugins: fastestmirror
base                                                                                                                                                                             | 3.6 kB  00:00:00
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#60 - "Peer's Certificate has expired."


failure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try.
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#60 - "Peer's Certificate has expired."

最后发现好像是虚拟机的服务器的时间不对,重新设置虚拟机的时间、:
参考:https://www.cnblogs.com/linyufeng/p/13191567.html


[root@localhost ~]# date
Wed Jul 29 11:25:29 CST 2020
[root@localhost ~]# date -s "2020-10-19 13:35:30"
Mon Oct 19 13:35:30 CST 2020
[root@localhost ~]# date
Mon Oct 19 13:35:31 CST 2020

然后再执行官方的安装脚本:OK 没问题!

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

4):验证安装

[root@localhost ~]# docker --version
Docker version 19.03.13, build 4484c46d9d
[root@localhost ~]#

5):配置开机启动:


[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]#

6):启动 Docker。


[root@localhost ~]# systemctl start docker
[root@localhost ~]#

7):运行一个简单的示例容器:docker run hello-world


[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
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/

PS:因为本地的没有这个容器,所有会从 https://hub.docker.com/进行拉取

8):查看所有的容器:


[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
d6087f654d9e        hello-world         "/hello"            4 minutes ago       Exited (0) 4 minutes ago                       practical_wozniak
[root@localhost ~]#

9):列出所有在运行的容器信息

root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost ~]#

CONTAINER ID: 容器 ID。

IMAGE: 使用的镜像。

COMMAND: 启动容器时运行的命令。

CREATED: 容器的创建时间。

STATUS: 容器状态。

状态有7种:

created(已创建)
restarting(重启中)
running(运行中)
removing(迁移中)
paused(暂停)
exited(停止)
dead(死亡)
PORTS: 容器的端口信息和使用的连接类型(tcp\udp)。

NAMES: 自动分配的容器名称。

其他命令查看帮助:

[root@localhost ~]# docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  engine      Manage the docker engine
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.
[root@localhost ~]#

命令大全的帮助参考:

https://www.runoob.com/docker/docker-command-manual.html

运行容器示docker run hello-world 流程说明

1)执行docker run hello-world,再本机查找hello-world镜像

  • 如果镜像存在,则已该镜像为模板生成容器实例运行
  • 如果镜像不存在,则会去远程的 https://hub.docker.com/进行查询
    2) 如远程仓库镜像查询,有无,有则拉取下载到本地,无则提示镜像不存在。

相关文章

网友评论

      本文标题:Centos下的纯命令记录Docker学习(1)-安装

      本文链接:https://www.haomeiwen.com/subject/tzukmktx.html