• <bdo id='6DLvS'></bdo><ul id='6DLvS'></ul>
    <tfoot id='6DLvS'></tfoot>
      <i id='6DLvS'><tr id='6DLvS'><dt id='6DLvS'><q id='6DLvS'><span id='6DLvS'><b id='6DLvS'><form id='6DLvS'><ins id='6DLvS'></ins><ul id='6DLvS'></ul><sub id='6DLvS'></sub></form><legend id='6DLvS'></legend><bdo id='6DLvS'><pre id='6DLvS'><center id='6DLvS'></center></pre></bdo></b><th id='6DLvS'></th></span></q></dt></tr></i><div id='6DLvS'><tfoot id='6DLvS'></tfoot><dl id='6DLvS'><fieldset id='6DLvS'></fieldset></dl></div>

      1. <small id='6DLvS'></small><noframes id='6DLvS'>

        <legend id='6DLvS'><style id='6DLvS'><dir id='6DLvS'><q id='6DLvS'></q></dir></style></legend>

        如何在 docker 上运行我的 python 脚本?

        时间:2023-09-10
              <tbody id='tcLqg'></tbody>

            <small id='tcLqg'></small><noframes id='tcLqg'>

            <legend id='tcLqg'><style id='tcLqg'><dir id='tcLqg'><q id='tcLqg'></q></dir></style></legend>

            1. <i id='tcLqg'><tr id='tcLqg'><dt id='tcLqg'><q id='tcLqg'><span id='tcLqg'><b id='tcLqg'><form id='tcLqg'><ins id='tcLqg'></ins><ul id='tcLqg'></ul><sub id='tcLqg'></sub></form><legend id='tcLqg'></legend><bdo id='tcLqg'><pre id='tcLqg'><center id='tcLqg'></center></pre></bdo></b><th id='tcLqg'></th></span></q></dt></tr></i><div id='tcLqg'><tfoot id='tcLqg'></tfoot><dl id='tcLqg'><fieldset id='tcLqg'></fieldset></dl></div>
                <bdo id='tcLqg'></bdo><ul id='tcLqg'></ul>

                1. <tfoot id='tcLqg'></tfoot>
                  本文介绍了如何在 docker 上运行我的 python 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在 docker 上运行我的 python 脚本.我尝试了不同的方法来做到这一点,但无法在 docker 上运行它.我的python脚本如下:

                  I am trying to run my python script on docker. I tried different ways to do it but not able to run it on docker. My python script is given below:

                  import os
                  
                  print ('hello') 
                  

                  我已经在我的 Mac 上安装了 docker.但是我想知道如何制作图像然后将其推送到 docker 之后我想在 docker 本身上拉并运行我的脚本.

                  I have already installed docker on my mac. But i want to know how i can make images and then push it to docker after that i wanna pull and run my script on docker itself.

                  推荐答案

                  好了,先为你的docker镜像创建一个具体的项目目录.例如:

                  Alright, first create a specific project directory for your docker image. For example:

                  mkdir /home/pi/Desktop/teasr/capturing
                  

                  在那里复制你的 dockerfile 和脚本并将当前上下文更改为该目录.

                  Copy your dockerfile and script in there and change the current context to this directory.

                  cp /home/pi/Desktop/teasr/capturing.py /home/pi/Desktop/teasr/dockerfile /home/pi/Desktop/teasr/capturing/
                  
                  cd /home/pi/Desktop/teasr/capturing
                  

                  这是为了最佳实践,因为 docker 引擎在构建时所做的第一件事就是读取整个当前上下文.

                  This is for best practice, as the first thing the docker-engine does on build, is read the whole current context.

                  接下来我们将查看您的 dockerfile.它现在应该是这样的:

                  Next we'll take a look at your dockerfile. It should look something like this now:

                  FROM python:latest
                  
                  WORKDIR /usr/local/bin
                  
                  COPY capturing.py .
                  
                  CMD ["capturing.py", "-OPTIONAL_FLAG"]
                  

                  接下来你需要做的是用一个聪明的名字来构建它.通常不鼓励使用点.

                  The next thing you need to do is build it with a smart name. Using dots is generally discouraged.

                  docker build -t pulkit/capturing:1.0 .
                  

                  接下来就是像以前一样运行映像.

                  Next thing is to just run the image like you've done.

                  docker run -ti --name capturing pulkit/capturing:1.0
                  

                  脚本现在在容器内执行,完成后可能会退出.

                  The script now get executed inside the container and will probably exit upon completion.

                  编辑后发现导致以下错误的问题:

                  Edit after finding the problem that created the following error:

                  standard_init_linux.go:195: exec 用户进程导致exec 格式错误"

                  树莓派下面有一个不同的架构(ARM 而不是 x86_64),这可能是问题所在,但不是.如果这是问题所在,将父图像切换到 FROM armhf/python 就足够了.

                  There's a different architecture beneath raspberry pi's (ARM instead of x86_64), which COULD'VE BEEN the problem, but wasn't. If that would've been the problem, a switch of the parent image to FROM armhf/python would've been enough.

                  来源

                  但是!错误不断发生.

                  所以这个问题的解决方案是在 python 脚本之上简单地缺少 Sha-Bang.脚本中的第一行需要是 #!/usr/bin/env python 应该可以解决问题.

                  So the solution to this problem is a simple missing Sha-Bang on top of the python script. The first line in the script needs to be #!/usr/bin/env python and that should solve the problem.

                  来源

                  这篇关于如何在 docker 上运行我的 python 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用多阶段构建减小 python (docker) 图像大小 下一篇:Docker 镜像错误:“/bin/sh: 1: [python,: not found"

                  相关文章

                  最新文章

                2. <tfoot id='Yv6Dv'></tfoot>

                  <small id='Yv6Dv'></small><noframes id='Yv6Dv'>

                  1. <legend id='Yv6Dv'><style id='Yv6Dv'><dir id='Yv6Dv'><q id='Yv6Dv'></q></dir></style></legend>
                      <bdo id='Yv6Dv'></bdo><ul id='Yv6Dv'></ul>

                  2. <i id='Yv6Dv'><tr id='Yv6Dv'><dt id='Yv6Dv'><q id='Yv6Dv'><span id='Yv6Dv'><b id='Yv6Dv'><form id='Yv6Dv'><ins id='Yv6Dv'></ins><ul id='Yv6Dv'></ul><sub id='Yv6Dv'></sub></form><legend id='Yv6Dv'></legend><bdo id='Yv6Dv'><pre id='Yv6Dv'><center id='Yv6Dv'></center></pre></bdo></b><th id='Yv6Dv'></th></span></q></dt></tr></i><div id='Yv6Dv'><tfoot id='Yv6Dv'></tfoot><dl id='Yv6Dv'><fieldset id='Yv6Dv'></fieldset></dl></div>