爆款云服务器低至4折,1核1G¥366/

安装 Docker

  • 删除旧版本 Docker

    sudo apt-get remove docker docker-engine docker.io
  • 添加 Docker 软件源

    sudo apt-get update
    sudo apt-get install apt-transport-https ca-certificates  curl software-properties-common
    curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  • 安装 Docker CE(社区版)

    sudo apt-get update -y
    sudo apt-get install docker-ce -y
  • 设置开机启动

    sudo systemctl enable docker
    sudo systemctl start docker
  • 把当前用户加入 docker 组

    sudo groupadd docker
    sudo usermod -aG docker $USER
  • 测试 docker

    docker run hello-world

使用 Docker 中国官方镜像加速

  • 编辑 vim /etc/docker/daemon.json 文件,添加以下内容:

    {
      "registry-mirrors": [
        "https://registry.docker-cn.com"
      ]
    }
  • 重启服务

    sudo systemctl daemon-reload
    sudo systemctl restart docker

Docker Compose

  • 安装 docker composer

    sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    
    sudo chmod +x /usr/local/bin/docker-compose
    
    docker-compose --version
  • 安装 docker composer 自动补全命令

    curl -L https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

参考链接

标签: Ubuntu, Docker