在Windows上构建的Raspberry上运行Docker映像

时间:2019-05-15 21:54:49

标签: docker raspberry-pi3

我想使用docker在Windows计算机上开发应用程序,然后将其发送到我的raspberry pi 3B +(并在群集中运行它们)。

但是我没有这样做:

我在Windows mashine上的python中设置了helloWorld:

app.py

from flask import Flask
import os
import socket

app = Flask(__name__)

@app.route("/")
def hello():

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>"

    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname())

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

requirements.txt

Flask

Dockerfile

FROM python
WORKDIR /app
COPY . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 80
ENV NAME World
CMD ["python", "app.py"]

运行

docker build --tag=hello .
docker run -p 4000:80 hello

工作就像一种魅力,甚至还可以通过

从我的注册表(在Raspberry上运行)推送和取回它
docker build -t somehostname/hello .
docker push somehostname/hello
//delete local container and image
docker run -p 4000:80 somehostname/hello

工作正常。

但是,当我使用树莓3B + SSH并运行时

sudo docker pull somehostname/hello
sudo docker run -p 4000:80 somehostname/hello

我得到:

standard_init_linux.go:207: exec user process caused "exec format error"

我读到这个错误,似乎与体系结构差异有关:我的Windows mashine使用x86-64,而raspberry 3B +使用ARM。

但是我构建的python映像是针对两种架构制作的,因此docker应该提取正确的映像。另外,将代码复制到我的树莓派上,构建图像并使用完全相同的代码行运行容器即可。

我还阅读了有关do​​cker manifest的信息,这是一项实验性功能,但是我不知道这对我有什么帮助,因为我使用的所有内容(我猜只是python)都已经是多体系结构,所以docker应该自己处理。

是否可以在不将代码复制到树莓派的情况下启动并运行我的应用?

更新:覆盆子的输出

user@somehostname:~ $ sudo docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            2                   c99846f41d25        2 months ago        22.1MB
user@somehostname:~ $ sudo docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
2af9cb1df776        registry:2          "/entrypoint.sh /etc…"   2 minutes ago       Up About a minute   0.0.0.0:5000->5000/tcp   registry
user@somehostname:~ $ sudo docker pull somehostname/hello:latest
latest: Pulling from hello
c5e155d5a1d1: Pull complete
221d80d00ae9: Pull complete
4250b3117dca: Pull complete
3b7ca19181b2: Pull complete
425d7b2a5bcc: Pull complete
dc3049ff3f44: Pull complete
472a6afc6332: Pull complete
5f79c90f8d7c: Pull complete
1051ee813012: Pull complete
38d05a77ad85: Pull complete
fe3cbf1eaf8a: Pull complete
c1e865e5779d: Pull complete
Digest: sha256:f7b31fff3116ef6621bf96fead8858ceb0768b502b2f3b221ab0f52cfc8039eb
Status: Downloaded newer image for somehostname/hello:latest
user@somehostname:~ $ sudo docker run -p 4000:80 somehostname/hello
standard_init_linux.go:207: exec user process caused "exec format error"
user@somehostname:~ $ sudo docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
somehostname/hello   latest              d7472edad23e        About an hour ago   938MB
registry            2                   c99846f41d25        2 months ago        22.1M
user@somehostname:~ $ sudo docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
2af9cb1df776        registry:2          "/entrypoint.sh /etc…"   11 minutes ago      Up 11 minutes       0.0.0.0:5000->5000/tcp   registry

1 个答案:

答案 0 :(得分:0)

您编写的几乎所有内容都正确,但是我确信Python映像是跨体系结构并不正确,您应该找到在所使用的Raspberry Pi设备上运行的Python映像。

IIRC 3s与Zeros的ARM体系结构也不相同,因此请小心使用正确的ARM体系结构。

您添加的exec format errror就是一个很好的指示。