原文链接:

https://www.cnblogs.com/chengmf/p/13122013.html

Docker基本命令

卸载旧版本Docker

# 卸载旧版本docker
root@dj-virtual-machine:/# apt-get remove docker docker-engine docker-ce docker.io	

# 清空旧版docker占用的内存
root@dj-virtual-machine:/# apt-get remove --auto-remove docker

# 更新系统源
root@dj-virtual-machine:/# apt-get update

配置安装环境

root@dj-virtual-machine:/# apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

添加阿里云的docker GPG密钥

root@dj-virtual-machine:/# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加阿里镜像源

root@dj-virtual-machine:/# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# 更新
root@dj-virtual-machine:/# apt-get update

查看有哪些版本

root@dj-virtual-machine:/# apt-cache madison docker-ce
 docker-ce | 5:20.10.1~3-0~ubuntu-groovy | http://mirrors.aliyun.com/docker-ce/linux/ubuntu groovy/stable amd64 Packages
 docker-ce | 5:20.10.0~3-0~ubuntu-groovy | http://mirrors.aliyun.com/docker-ce/linux/ubuntu groovy/stable amd64 Packages
root@dj-virtual-machine:/#

安装最新版/指定版本

# 安装最新版
root@dj-virtual-machine:/# apt-get install -y docker-ce

# 安装 5:20.10.0~3-0~ubuntu-groovy 版
root@dj-virtual-machine:/# apt-get install -y docker-ce=5:20.10.0~3-0~ubuntu-groovy

重启Docker

root@dj-virtual-machine:/# service docker restart
# 或者
root@dj-virtual-machine:/# systemctl restart docker

查看Docke版本信息

root@dj-virtual-machine:/# docker --version
# 或者
root@dj-virtual-machine:/# docker version
# 或者
root@dj-virtual-machine:/# docker info

配置阿里容器镜像加速器

阿里云-容器镜像服务-镜像加速器

  • 安装/升级Docker客户端

推荐安装1.10.0以上版本的Docker客户端,参考文档 docker-ce

  • 配置镜像加速器

针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

root@dj-virtual-machine:/# sudo mkdir -p /etc/docker
root@dj-virtual-machine:/# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://eh4foh5p.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://eh4foh5p.mirror.aliyuncs.com"]
}
root@dj-virtual-machine:/# sudo systemctl daemon-reload
root@dj-virtual-machine:/# sudo systemctl restart docker
root@dj-virtual-machine:/#

验证docker-ce是否安装成功

  • 安装成功显示:
root@dj-virtual-machine:/# sudo 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/

root@dj-virtual-machine:/#

安装docker-compose

  • 安装pip
root@dj-virtual-machine:/# apt install python3-pip
  • 更换pip源

原文参见:https://blog.csdn.net/u012798683/article/details/107316227/

# 使用pip安装第三方库时,更换pip镜像源解决安装速度慢的问题
# 1、创建.pip隐藏文件夹
root@dj-virtual-machine:/# mkdir ~/.pip
# 2、进入文件夹并编辑pip.conf文件
root@dj-virtual-machine:/# vim ~/.pip/pip.conf
# 3、编辑配置,添加如下
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
# 4、:wq 保存退出

注意:新版ubuntu要求使用https源。

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

豆瓣:http://pypi.douban.com/simple/

  • 更新
# 更新软件库
root@dj-virtual-machine:/# apt-get update
# 更新pip
root@dj-virtual-machine:/# pip3 install --upgrade pip
  • 安装docker-compose
root@dj-virtual-machine:/# pip3 install docker-compose
  • 查看docker-compose版本
root@dj-virtual-machine:/# docker-compose --version
docker-compose version 1.27.4, build unknown
root@dj-virtual-machine:/#

分类: Linux

Deng Jia

Keep Moving.

0 条评论

发表评论

电子邮件地址不会被公开。