跳转到主要内容
首页

用户帐户菜单

  • 登录

主导航

  • 首页
  • 小公司运营
  • 网站建设
  • 创业杂谈
  • 兼职赚钱
  • 小微企业信息化
  • 手册教程
    • 《大伟哥的Drupal 8建站指南》
    • 《通过JohnChow.Com在网上赚钱》
  • 关于

面包屑

  • 首页
  • 在 WSL2 Debian 10上安装原生 Docker

在 WSL2 Debian 10上安装原生 Docker

By 大伟哥 | 2021-03-30,周二, 21:53

以下内容结合docker官网文档及网上错误解决方案,在wsl2 Debian 10 上测试通过。

删除旧版本的docker

旧版本的docker名称可能叫docker, docker.io, 或者docker-engine, 如果你之前安装过旧的版本,需要首先卸载:

sudo apt remove docker docker-engine docker.io containerd runc
[sudo] password for david:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'docker-engine' is not installed, so not removed
E: Unable to locate package containerd

我们现在安装的Docker是社区版的,被称为docker-ce. 有很多种方法可以在 Debian 上安装 Docker-ce, 这里我们直接用Docker仓库(Docker repository)进行安装。

首先需要更新源,并安装依赖包:

 sudo apt update
 sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

添加 Docker 的官方 GPG 密钥:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

指定docker仓库性质为稳定版:

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装docker:

 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

运行测试出错

sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

排查过程:

sudo service docker start
grep: /etc/fstab: No such file or directory
[ ok ] Starting Docker: docker.
sudo service docker status [FAIL]
Docker is not running ... failed!

网上找到解决方案,方法如下:


sudo touch /etc/fstab
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

问题解决,运行hello world状况正常:

sudo service docker start
[ ok ] Starting Docker: docker.
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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/
  • 添加新评论
  • 1852 阅读
WSL2
Linux

评论

docker wang

3 years 8 months 之前

永久连接

WSL2用Debian装docker…

  • 回复

添加新评论

此字段内容将保密,不会被其他人看见。
关于文本格式
  • 不允许使用HTML标签。
CAPTCHA
1 + 0 =
计算出这道简单的算术题并键入答案。例如、1+3,就输入 4。
发布评论前,请通过下面的验证,以免被当作垃圾评论机器人屏蔽。

搜索

沪ICP备17000093号-1

公安备案沪公网安备 31011402008254号

© 2016-2022 大伟哥博客版权所有