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

<legend id='8Ptgr'><style id='8Ptgr'><dir id='8Ptgr'><q id='8Ptgr'></q></dir></style></legend>

<small id='8Ptgr'></small><noframes id='8Ptgr'>

  • <tfoot id='8Ptgr'></tfoot>

        <bdo id='8Ptgr'></bdo><ul id='8Ptgr'></ul>

        Docker交互模式和执行脚本

        Docker interactive mode and executing script(Docker交互模式和执行脚本)

            <tbody id='JtB1K'></tbody>

                <tfoot id='JtB1K'></tfoot>

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

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

                • 本文介绍了Docker交互模式和执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have a Python script in my docker container that needs to be executed, but I also need to have interactive access to the container once it has been created ( with /bin/bash ).

                  I would like to be able to create my container, have my script executed and be inside the container to see the changes/results that have occurred (no need to manually execute my python script).

                  The current issue I am facing is that if I use the CMD or ENTRYPOINT commands in the docker file I am unable to get back into the container once it has been created. I tried using docker start and docker attach but I'm getting the error:

                  sudo docker start containerID
                  sudo docker attach containerID
                  "You cannot attach to a stepped container, start it first"
                  

                  Ideally, something close to this:

                  sudo docker run -i -t image /bin/bash python myscript.py
                  


                  Assume my python script contains something like (It's irrelevant what it does, in this case it just creates a new file with text):

                  open('newfile.txt','w').write('Created new file with text
                  ')
                  

                  When I create my container I want my script to execute and I would like to be able to see the content of the file. So something like:

                  root@66bddaa892ed# sudo docker run -i -t image /bin/bash
                  bash4.1# ls
                  newfile.txt
                  bash4.1# cat newfile.txt
                  Created new file with text
                  bash4.1# exit
                  root@66bddaa892ed#
                  

                  In the example above my python script would have executed upon creation of the container to generate the new file newfile.txt. This is what I need.

                  解决方案

                  My way of doing it is slightly different with some advantages. It is actually multi-session server rather than script but could be even more usable in some scenarios:

                  # Just create interactive container. No start but named for future reference.
                  # Use your own image.
                  docker create -it --name new-container <image>
                  
                  # Now start it.
                  docker start new-container
                  
                  # Now attach bash session.
                  docker exec -it new-container bash
                  

                  Main advantage is you can attach several bash sessions to single container. For example I can exec one session with bash for telling log and in another session do actual commands.

                  BTW when you detach last 'exec' session your container is still running so it can perform operations in background

                  这篇关于Docker交互模式和执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

                      • <tfoot id='nrWRc'></tfoot>
                      • <legend id='nrWRc'><style id='nrWRc'><dir id='nrWRc'><q id='nrWRc'></q></dir></style></legend>

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

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

                          <bdo id='nrWRc'></bdo><ul id='nrWRc'></ul>