linux 安装 docker及阿里云下载加速配置

linux centos7环境下安装docker 详细过程

文章目录

  • 1. 下载安装
    • 1.1 第一种方法(推荐, 非常方便快捷)
    • 1.2 第二种方法:
    • 两种安装方法的区别
  • 2. 验证安装及docker命令使用说明
  • 3. 配置docker镜像,以使下载加速
    • 3.1 另一种方法
    • 3.2 阿里云镜像加速

1. 下载安装

1.1 第一种方法(推荐, 非常方便快捷)

[root@laoliu ~]# yum -y install docker-io
...
已安装:
  docker.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos                                                                                       

作为依赖被安装:
  atomic-registries.x86_64 1:1.22.1-26.gitb507039.el7.centos               container-selinux.noarch 2:2.74-1.el7                        
  container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7                 containers-common.x86_64 1:0.1.31-8.gitb0b750d.el7.centos    
  docker-client.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos                   docker-common.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos       
  oci-register-machine.x86_64 1:0-6.git2b44233.el7                         oci-systemd-hook.x86_64 1:0.1.18-3.git8787307.el7_6          
  oci-umount.x86_64 2:2.3.4-2.git87f9237.el7                               python-pytoml.noarch 0:0.1.14-1.git7dea353.el7               
  subscription-manager-rhsm-certificates.x86_64 0:1.21.10-3.el7.centos    

完毕!
[root@laoliu ~]# 

安装过程比较慢, 出现已安装: ... 到完毕!表示安装完成

1.2 第二种方法:

[root@laoliu ~]# cd /usr/local/src/
[root@laoliu src]# sudo wget -qO- https://get.docker.com | sh
[root@laoliu src]# sudo usermod -aG docker user
[root@laoliu src]# docker info

命令解析下:

  • wget -qO- 命令行下载工具, 并将结果标准输出到屏幕上
  • | sh 下载完后,交由sh来执行
  • sudo usermod -aG docker user是将user用户添加到docker用户组中, 只要是在docker用户组中的用户,都可以使用docker.

两种安装方法的区别

1.1 安装完成后没有自行启动docker服务,1.2安装后完自行启动docker服务

2. 验证安装及docker命令使用说明

[root@laoliu ~]# docker

Usage:	docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -H, --host list          Daemon socket(s) to connect to (default [])
  -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:
  container   Manage containers
  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
  volume      Manage volumes

Commands:
  attach      Attach 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 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@laoliu ~]# 

表示正确安装并返回命令使用说明

3. 配置docker镜像,以使下载加速

[root@laoliu ~]# sudo echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://hub-mirror.c.163.com\"" >> /etc/default/docker

3.1 另一种方法

  • /etc/default/目录下生成docker文件:
  • 内容为:`DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=http://hub-mirror.c.163.com"

3.2 阿里云镜像加速

参考阿里云官方网站:

[root@ecs docker]# pwd
/etc/docker
[root@ecs docker]# cat daemon.json 
{
  "registry-mirrors": ["https://mirror.aliyuncs.com"],   # 每个人专属的阿里云docker镜像地址, 请在阿里云官网申请
  "log-driver": "json-file",  # 在此配置日志大小
  "log-opts": {
    "max-size": "1m",
    "max-file": "3"
  }
}
[root@ecs docker]#  sudo systemctl daemon-reload
[root@ecs docker]#  sudo systemctl restart docker

`

你可能感兴趣的:(docker进阶,docker,linux,安装)