【2023.11.5 最新更新:真·一键安装docker和docker compose】在ubuntu上安装docker和docker compose(含python安装教程)

  看了网上比较多方法,基本都很繁杂,这里总结一下我找到的比较快的在ubuntu上安装docker的方法

注意:有在网上看到说sudo apt install docker.io一行代码解决的做法,但实际上这样安装的是docker的旧版本(是如下文中需要卸载的旧版本之一)


安装docker

法一:真·一键安装docker

发现了一行命令一键安装docker的方法,用下面的检验方法也没问题,那就是:
snap install docker

法二:使用官方安装脚本自动安装

先卸载旧版本(如果有安装的话,Docker 的旧版本指 docker,docker.io 或 docker-engine ):sudo apt-get remove docker docker-engine docker.io containerd runc

如果不确定自己有没有安装就在版就都输一下这条命令,没安装输了这命令也没影响

输入安装命令

  • curl -fsSL https://test.docker.com -o test-docker.sh
  • sudo sh test-docker.sh

测试是否安装成功:
测试一:
输入命令:sudo docker run hello-world

若输出以下内容则安装成功

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
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/

测试二:输入docker version命令,显示如下信息则说明安装成功在这里插入图片描述


卸载docker

删除安装包:
sudo apt-get purge docker-ce

删除镜像、容器、配置文件等内容:
sudo rm -rf /var/lib/docker

安装docker compose

我这个方法需要先安装python,如果已经安装了则跳过安装python和pip的步骤

安装python

依次输入如下命令

sudo apt update
sudo apt install python3

验证安装是否成功
python3 --version

显示如下版本号信息则安装成功

Python 3.10.12

安装pip命令

sudo apt install python3-pip

验证是否安装成功:输入pip list会显示已安装的依赖包

安装docker compose

只需要一行命令:
pip install docker-compose

验证安装是否成功:
docker-compose version

显示如下版本号则成功:

Docker Compose version v2.17.2

参考:
安装python
docker-compose教程
Docker和Docker Compose关系及应用

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值