启动 Docker 容器时出错(WSL、docker-ce、Ubuntu 16.04) [英] Error starting Docker container (WSL, docker-ce, Ubuntu 16.04)

查看:92
本文介绍了启动 Docker 容器时出错(WSL、docker-ce、Ubuntu 16.04)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Windows [版本 10.0.17134.285],Ubuntu 16.04 (WSL),docker-ce(稳定)

Microsoft Windows [Version 10.0.17134.285], Ubuntu 16.04 (WSL), docker-ce (stable)

我正在按照此处的说明进行操作 - https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawless.我选择了稳定"而不是边缘".我用

I am following the instructions here - https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly. I opted for "stable" rather than "edge". I mounted the c drive mapping manually with

sudo mkdir /c
sudo mount --bind /mnt/c /c

而不是 WSL 配置文件方式,因为我不确定我是否想要它用于我的所有 WSL 实例.除此之外,我按照说明进行操作.

rather than the WSL config file way, because I wasn't sure if I wanted it for ALL my WSL instances. Other than that, I followed the instructions.

我已经启动了 Docker 守护进程

I have started the Docker daemon with

sudo cgroupfs-mount
sudo dockerd -H tcp://0.0.0.0:2375 --tls=false

当我尝试用

docker run -d -p 27017:27017 --name testDB mongo:3.4

我明白了

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:46: preparing rootfs caused \\\"invalid argument\\\"\"": unknown.

并且我无法使用 localhost:27017 连接到容器上的 MongoDB.

and I cannot connect to the MongoDB on the container using localhost:27017.

docker ps -a

节目

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
e115d1c409a3        mongo:3.4           "docker-entrypoint.s…"   6 seconds ago       Created             0.0.0.0:27017->27017/tcp   testDB

docker info

节目

Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: <unknown>
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Kernel Version: 4.4.0-17134-Microsoft
Operating System: Ubuntu 16.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.9GiB
Name: DESKTOP-4F100D9
ID: EFH2:O3RT:3OO4:27P5:ZNK7:N5JW:WE5M:4VSK:QREN:YCV4:GSYG:ZDTR
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory limit support
WARNING: No oom kill disable support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
WARNING: No cpu shares support
WARNING: No cpuset support

知道我做错了什么以及如何解决吗?

Any ideas what I did wrong and how to fix it?

(我需要在 Linux(WSL) 下运行 Docker - 我不能在 Windows 上使用 Docker,因为我们使用的是 VirtualBox,并且 Hyper-V 被禁用)

(I need to run Docker under Linux(WSL) - I cannot use Docker for Windows because we are using VirtualBox, and Hyper-V is disabled)

推荐答案

目前,您不能直接从 WSL 使用 docker daemon.有几个问题,主要是网络问题.它仅适用于像 hello world 这样的简单图像(Reddit topic)

Currently, you cannot use docker daemon directly from WSL. There are several issues, mostly with networking. It works only for simple images like hello world (Reddit topic)

您可以做的是从 WSL 连接到 Windows 中的 docker 守护进程.所以按照教程,你提到的很好,但如果你用 VirtualBox 运行它,你必须启动 default 机器或创建并启动一个新机器.这台 docker 机器将成为你的守护进程.

What you can do, is connect from WSL to docker daemon in windows. So following the tutorial, you mentioned is fine, but if you're running it with VirtualBox you have to either start default machine or create and start a new one. This docker machine will be your daemon.

默认情况下 docker-machine 命令在 WSL 中无法正常工作,但您可以通过将此代码放入例如~/.bashrc 文件

By default docker-machine command is not working correctly in WSL, but you can make it works by putting this code to e.g. ~/.bashrc file

# Ability to run docker-machine command properly from WSL
function docker-machine()
{
    if [ $1 == "env" ]; then
            docker-machine.exe $1 $2 --shell bash | sed 's/C:/\/c/' | sed 's/\\/\//g' | sed 's:#.*$::g' | sed 's/"//g'
            printf "# Run this command to configure your shell:\n"
            printf "# eval \"\$(docker-machine $1 $2)\"\n"
    else
            docker-machine.exe "$@"
    fi
}
export -f docker-machine

运行 source ~/.bashrc 或重新打开 bash 后,您可以运行:

After running source ~/.bashrc or reopening the bash you can run:

  • docker-machine start default - 将启动机器
  • eval $(docker-machine env default) - 将你的 bash 会话连接到机器
  • docker-machine start default - will start machine
  • eval $(docker-machine env default) - will connect your bash session to the machine

然后你应该能够运行所有 docker 的东西,比如

and then you should be able to run all the docker stuff like

  • docker ps
  • docker run -it alpine sh
  • docker build

docker 机器将一直运行,直到您停止它或关闭您的 PC.如果您打开一个新的 bash 会话(窗口),您必须只运行 eval $(docker-machine env default) 才能将您的新会话连接到机器.

The docker machine will run until you either stop it or you shut down your PC. If you open a new bash session (window), you have to run just eval $(docker-machine env default) in order to connect your new session to the machine.

希望有帮助.:)

这篇关于启动 Docker 容器时出错(WSL、docker-ce、Ubuntu 16.04)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆