当前位置:   article > 正文

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

ubuntu 安装docker-compose

  看了网上比较多方法,基本都很繁杂,这里总结一下我找到的比较快的在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/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

测试二:输入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
  • 1
  • 2

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

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

Python 3.10.12
  • 1

安装pip命令

sudo apt install python3-pip

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

安装docker compose

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

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

显示如下版本号则成功:

Docker Compose version v2.17.2
  • 1

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/160951
推荐阅读
相关标签
  

闽ICP备14008679号