Ubuntu 安装docker记录

Add Docker’s official GPG key:

  1. 更新包管理器
sudo apt update
  1. 安装必要的基础包
sudo apt install ca-certificates curl
  1. 创建密钥环目录
sudo install -m 0755 -d /etc/apt/keyrings
  1. 下载 Docker 官方 GPG 公钥
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

可能会出现Unable to establish SSL connection,则从其它源下载,如阿里云镜像源。

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o gpg

再移动到正确位置。

sudo mv gpg /etc/apt/keyrings/docker.asc
  1. 设置密钥文件权限
sudo chmod a+r /etc/apt/keyrings/docker.asc

Add the repository to Apt sources:

  1. 为 Ubuntu 系统添加 Docker 的官方 APT 软件源
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
  1. 再次更新
sudo apt update
  1. 安装docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. 查看状态
sudo systemctl status docker
  1. 测试
    拉取镜像。
sudo docker pull hello-world

若失败,则更换源。

sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
EOF

并更新状态。

sudo systemctl daemon-reload
sudo systemctl restart docker

重新拉取,并部署sudo docker run hello-world

### 安装 Docker 并配置 Ubuntu 环境 #### 安装 Docker Desktop for Mac 为了在 macOS 上使用 Docker,需先下载并安装 Docker Desktop。对于 Apple Silicon (M1 芯片) 的设备,官方已经提供了适配版本。 访问 [Docker Desktop](https://www.docker.com/products/docker-desktop)[^4] 页面获取最新版的应用程序包,并按照提示完成安装过程。 #### 启动 Docker 服务 安装完成后,在应用程序文件夹中找到 Docker 图标双击打开。首次启动时可能需要输入管理员密码授权应用权限。等待初始化完毕后,可以通过点击菜单栏中的鲸鱼图标确认状态是否正常运行。 #### 获取 Ubuntu 镜像 通过命令行终端执行 `docker pull ubuntu:20.04` 来拉取指定版本的 Ubuntu 镜像[^1]。这一步骤会自动从远程仓库下载所需的资源到本地缓存区以便后续创建容器实例。 #### 创建并进入 Ubuntu 容器 利用以下指令快速建立一个新的基于所选镜像的操作系统环境: ```bash docker run -it --name my_ubuntu_container ubuntu:20.04 /bin/bash ``` 上述命令将会启动一个交互式的 Bash shell 终端连接至新生成的名字叫作 "my_ubuntu_container" 的容器内部。 #### 自定义设置与持久化存储 如果希望保存工作数据或软件包更新,则应该考虑挂载卷(volume),即把宿主机上的某个目录映射给容器内的路径用于长期保持更改记录。例如: ```bash docker run -v ~/local_folder:/mnt/data -it --name my_persistent_ubuntu_container ubuntu:20.04 /bin/bash ``` 这里 `-v` 参数指定了外部共享位置 `/mnt/data` 将指向用户家目录下的 `~/local_folder` 文件夹[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值