当前位置:  首页>> 技术小册>> Docker零基础到实战

使用一键安装脚本安装:

  1. 官方脚本安装(使用aliyun镜像)
    $ curl -fsSL https://get.docker.com | bash -s docker —mirror Aliyun

  2. Dcloud安装(国内环境)
    $ curl -sSL https://get.daocloud.io/docker | sh


手动安装docker

Ubuntu搭建Docker

Docker目前支持的最低Ubuntu版本为14.04 LTS,但实际上从稳定性上考虑,推荐使用16.04 LTS或18.0.4 LTS版本,或者20.04LTS版本,并且系统内核越新越好,以支持Docker最新的特性。
官方文档:
https://docs.docker.com/engine/install/ubuntu/

更换源(可选,如果更换为清华源,则后面的安装步骤参数需要指定为清华源)

移除系统中可能存在的旧版本的Docker

  1. $ sudo apt-get remove docker docker-engine docker.io containerd runc

安装可以通过https使用仓库的一些相关包

  1. $ sudo apt-get install \
  2. apt-transport-https \
  3. ca-certificates \
  4. curl \
  5. gnupg-agent \
  6. software-properties-common

添加GPG key
清华源:

  1. $ curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

ubuntu源:

  1. $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加docker-ce的仓库
清华源:

  1. $ sudo add-apt-repository \
  2. "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
  3. $(lsb_release -cs) stable"

ubuntu源:

  1. $ echo \
  2. "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  3. $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装docker
安装前需要再次更新包索引:

  1. $ sudo apt update
  1. $ sudo apt-get install docker-ce docker-ce-cli containerd.io

更换docker镜像源:(可选)

  1. $ sudo vim /etc/docker/daemon.json
  1. {
  2. "registry-mirrors": ["http://hub-mirror.c.163.com"]
  3. }

启动docker

  1. sudo systemctl start docker

配置Docker用户

为了避免每次使用Docker命令时都需要切换到特权身份,可以将当前用户加入安装中自动创建的docker用户组

  1. $ sudo usermod -aG docker $USER

更新docker组

  1. $ newgrp docker

该分类下的相关小册推荐: