Ubuntu安装docker和docker compose

简介: Ubuntu安装docker容器化环境

前置准备

使用自有或购买一台Ubuntu云服务器

阿里云服务器配置指南:【Linux系统实例快速入门】

注意选择ubuntu镜像初始化服务器

Ubuntu 安装docker

示例Ubuntu服务器版本: Ubuntu 20.04 LTS (GNU/Linux 5.4.0-139-generic x86\_64)

移除旧版本 docker

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

如果没有安装过docker则输出如下所示

Hit:1 http://mirrors.tencentyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.tencentyun.com/ubuntu focal-security InRelease
Hit:3 http://mirrors.tencentyun.com/ubuntu focal-updates InRelease
Reading package lists... Done

使用apt repository 安装

更新apt包索引

sudo apt-get update

安装依赖包

sudo apt-get install ca-certificates curl gnupg

添加Docker的官方GPG密钥

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

设置docker存储库

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装 Docker Engine

更新apt包索引

sudo apt-get update

安装最新版本的docker和docker compose

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

验证docker engine是否安装成功

sudo docker run hello-world

输出如下所示

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0
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 和docker compose 版本

sudo docker version

输出如下所示

Client: Docker Engine - Community
 Version:           23.0.6
 API version:       1.42
 Go version:        go1.19.9
 Git commit:        ef23cbc
 Built:             Fri May  5 21:18:22 2023
 OS/Arch:           linux/amd64
 Context:           default
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
ubuntu@VM-2-6-ubuntu:~$ sudo docker version
Client: Docker Engine - Community
 Version:           23.0.6
 API version:       1.42
 Go version:        go1.19.9
 Git commit:        ef23cbc
 Built:             Fri May  5 21:18:22 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.6
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.9
  Git commit:       9dbdbd4
  Built:            Fri May  5 21:18:22 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
sudo docker compose version

如下所示

Docker Compose version v2.17.3

配置非root管理docker

创建docker组

sudo groupadd docker

添加当前用户到docker组

sudo usermod -aG docker $USER

激活对组的更改

newgrp docker

验证不使用sudo 运行docker 命令

docker images

输出如下所示

REPOSITORY    TAG       IMAGE ID       CREATED      SIZE
hello-world   latest    9c7a54a9a43c   9 days ago   13.3kB

配置开机自启动

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

参考链接:https://docs.docker.com/engine/install/ubuntu/

目录
相关文章
|
11天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
82 42
|
4天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
52 20
|
14天前
|
Linux Docker 容器
安装docker-18.06报错Error: libseccomp conflicts with docker-18.06
通过这些步骤,您可以成功在CentOS上安装Docker 18.06,并解决libseccomp的冲突问题。这些方法确保系统兼容性,并保证Docker的正常运行。
52 27
|
4天前
|
Ubuntu API 网络虚拟化
ubuntu22 编译安装docker,和docker容器方式安装 deepseek
本脚本适用于Ubuntu 22.04,主要功能包括编译安装Docker和安装DeepSeek模型。首先通过Apt源配置安装Docker,确保网络稳定(建议使用VPN)。接着下载并配置Docker二进制文件,创建Docker用户组并设置守护进程。随后拉取Debian 12镜像,安装系统必备工具,配置Ollama模型管理器,并最终部署和运行DeepSeek模型,提供API接口进行交互测试。
91 15
|
3天前
|
消息中间件 Kafka Docker
docker compose 安装 kafka
通过本文的步骤,您可以快速在本地使用 Docker Compose 安装并配置 Kafka 和 Zookeeper。Docker Compose 简化了多容器应用的管理,方便快速搭建和测试分布式系统。
26 2
|
4月前
|
Ubuntu Docker 容器
本地wsl的Ubuntu安装docker,不使用docker桌面版
本文提供了在WSL的Ubuntu环境中安装Docker引擎的步骤,包括安装引擎、配置iptables以及启动Docker服务。
312 2
|
5月前
|
Ubuntu Linux Docker
Ubuntu 18.04 安装Docker实战案例
关于如何在Ubuntu 18.04系统上安装Docker的实战案例,包括安装步骤、配置镜像加速以及下载和运行Docker镜像的过程。
595 3
Ubuntu 18.04 安装Docker实战案例
|
6月前
|
Ubuntu Docker 索引
2024年最新版 Ubuntu 20+ 上安装 Docker
这篇文章提供了在Ubuntu 20+版本上安装Docker的详细步骤,包括更新软件包索引、安装依赖包、添加Docker官方GPG密钥、设置Docker稳定版仓库、安装Docker CE以及验证安装是否成功,并指导如何将用户添加到docker组以非root用户身份运行Docker。
|
6月前
|
Ubuntu Linux 持续交付
在Ubuntu 16.04上安装Docker Compose的方法
在Ubuntu 16.04上安装Docker Compose的方法
161 1
|
6月前
|
Ubuntu Shell 应用服务中间件
在Ubuntu 14.04上安装和使用Docker Compose的方法
在Ubuntu 14.04上安装和使用Docker Compose的方法
122 1