久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <tfoot id='ytRIo'></tfoot>

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

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

    1. <legend id='ytRIo'><style id='ytRIo'><dir id='ytRIo'><q id='ytRIo'></q></dir></style></legend>

      1. 如何通過 dockerfile 在 ENTRYPOINT 之前執行 shell 命令

        How to execute a shell command before the ENTRYPOINT via the dockerfile(如何通過 dockerfile 在 ENTRYPOINT 之前執行 shell 命令)

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

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

              1. <legend id='ExaxE'><style id='ExaxE'><dir id='ExaxE'><q id='ExaxE'></q></dir></style></legend>
                  <tbody id='ExaxE'></tbody>

                • 本文介紹了如何通過 dockerfile 在 ENTRYPOINT 之前執行 shell 命令的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的 nodejs 項目有以下文件

                  I have the following file for my nodejs project

                  FROM node:boron
                  
                  # Create app directory
                  RUN mkdir -p /usr/src/app
                  WORKDIR /usr/src/app
                  
                  # Install app dependencies
                  COPY package.json /usr/src/app/
                  RUN npm install
                  
                  
                  
                  # Bundle app source
                  COPY . /usr/src/app
                  
                  # Replace with env variable
                  RUN envsubs < fil1 > file2
                  
                  EXPOSE 8080
                  CMD [ "npm", "start" ]
                  

                  我使用 -e 標志運行 docker 容器,提供環境變量

                  I run the docker container with the -e flag providing the environment variable

                  但我沒有看到替代品.當 env 變量可用時會執行 Run c 命令嗎?

                  But I do not see the replacement. Will the Run ccommand be excuted when the env variable is available?

                  推薦答案

                  圖像是不可變的

                  Dockerfile 定義了鏡像的構建過程.一旦構建,圖像是不可變的(無法更改).運行時變量不會被烘焙到這個不可變的圖像中.所以 Dockerfile 是解決這個問題的錯誤地方.

                  Images are immutable

                  Dockerfile defines the build process for an image. Once built, the image is immutable (cannot be changed). Runtime variables are not something that would be baked into this immutable image. So Dockerfile is the wrong place to address this.

                  您可能想要做的是用您自己的腳本覆蓋默認的 ENTRYPOINT,并讓該腳本對環境變量執行一些操作.由于入口點腳本將在運行時(容器啟動時)執行,因此這是收集環境變量并對其進行處理的正確時間.

                  What you probably want to to do is override the default ENTRYPOINT with your own script, and have that script do something with environment variables. Since the entrypoint script would execute at runtime (when the container starts), this is the correct time to gather environment variables and do something with them.

                  首先,您需要調整 Dockerfile 以了解入口點腳本.雖然 Dockerfile 不直接參與處理環境變量,但它仍然需要了解該腳本,因為該腳本將被烘焙到您的鏡像中.

                  First, you need to adjust your Dockerfile to know about an entrypoint script. While Dockerfile is not directly involved in handling the environment variable, it still needs to know about this script, because the script will be baked into your image.

                  Dockerfile:

                  COPY entrypoint.sh /entrypoint.sh
                  RUN chmod +x /entrypoint.sh
                  
                  ENTRYPOINT ["/entrypoint.sh"]
                  CMD ["npm", "start"]
                  

                  現在,編寫一個入口點腳本,它會在命令運行之前完成所需的任何設置,最后,exec 命令本身.

                  Now, write an entrypoint script which does whatever setup is needed before the command is run, and at the end, exec the command itself.

                  entrypoint.sh:

                  #!/bin/sh
                  
                  # Where $ENVSUBS is whatever command you are looking to run
                  $ENVSUBS < fil1 > file2
                  
                  npm install
                  
                  # This will exec the CMD from your Dockerfile, i.e. "npm start"
                  exec "$@"
                  

                  在這里,我已包含 npm install,因為您在評論中詢問了這個問題.我會注意到這將在每次運行時運行 npm install .如果合適的話,很好,但我想指出它每次都會運行,這會給您的啟動時間增加一些延遲.

                  Here, I have included npm install, since you asked about this in the comments. I will note that this will run npm install on every run. If that's appropriate, fine, but I wanted to point out it will run every time, which will add some latency to your startup time.

                  現在重新構建您的映像,因此入口點腳本是其中的一部分.

                  Now rebuild your image, so the entrypoint script is a part of it.

                  入口點腳本知道如何使用環境變量,但您仍然需要告訴 Docker 在運行時導入該變量.您可以使用 -e 標志到 docker run 來執行此操作.

                  The entrypoint script knows how to use the environment variable, but you still have to tell Docker to import the variable at runtime. You can use the -e flag to docker run to do so.

                  docker run -e "ENVSUBS=$ENVSUBS" <image_name>
                  

                  這里告訴Docker定義一個環境變量ENVSUBS,賦值給當前shell環境$ENVSUBS的值.

                  Here, Docker is told to define an environment variable ENVSUBS, and the value it is assigned is the value of $ENVSUBS from the current shell environment.

                  我將對此進行詳細說明,因為在評論中,您似乎對這如何組合在一起有些模糊.

                  I'll elaborate a bit on this, because in the comments, it seemed you were a little foggy on how this fits together.

                  當 Docker 啟動一個容器時,它會在容器內執行一個(并且只有一個)命令.該命令變為 PID 1,就像典型 Linux 系統上的 initsystemd 一樣.該進程負責運行容器所需的任何其他進程.

                  When Docker starts a container, it executes one (and only one) command inside the container. This command becomes PID 1, just like init or systemd on a typical Linux system. This process is responsible for running any other processes the container needs to have.

                  默認情況下,ENTRYPOINT/bin/sh -c.您可以在 Dockerfile 或 docker-compose.yml 中覆蓋它,或者使用 docker 命令.

                  By default, the ENTRYPOINT is /bin/sh -c. You can override it in Dockerfile, or docker-compose.yml, or using the docker command.

                  當容器啟動時,Docker 運行入口點命令,并將命令 (CMD) 作為參數列表傳遞給它.之前,我們將自己的 ENTRYPOINT 定義為 /entrypoint.sh.這意味著在您的情況下,這是 Docker 啟動時將在容器中執行的內容:

                  When a container is started, Docker runs the entrypoint command, and passes the command (CMD) to it as an argument list. Earlier, we defined our own ENTRYPOINT as /entrypoint.sh. That means that in your case, this is what Docker will execute in the container when it starts:

                  /entrypoint.sh npm start
                  

                  因為 ["npm", "start"] 被定義為命令,這就是作為參數列表傳遞給入口點腳本的內容.

                  Because ["npm", "start"] was defined as the command, that is what gets passed as an argument list to the entrypoint script.

                  因為我們使用 -e 標志定義了一個環境變量,所以這個入口點腳本(及其子腳本)將可以訪問該環境變量.

                  Because we defined an environment variable using the -e flag, this entrypoint script (and its children) will have access to that environment variable.

                  在入口點腳本的最后,我們運行 exec "$@".因為 $@ 擴展為傳遞給腳本的參數列表,這將運行

                  At the end of the entrypoint script, we run exec "$@". Because $@ expands to the argument list passed to the script, this will run

                  exec npm start
                  

                  并且由于 exec 將其參數作為命令運行,用自身替換當前進程,當你完成時,npm start 變為 PID1 在您的容器中.

                  And because exec runs its arguments as a command, replacing the current process with itself, when you are done, npm start becomes PID 1 in your container.

                  在評論中,您詢問是否可以定義多個 CMD 條目來運行多個操作.

                  In the comments, you asked whether you can define multiple CMD entries to run multiple things.

                  您只能定義一個 ENTRYPOINT 和一個 CMD.在構建過程中根本不使用這些.與 RUNCOPY 不同,它們不會在構建期間執行.它們在構建后作為元數據項添加到圖像中.

                  You can only have one ENTRYPOINT and one CMD defined. These are not used at all during the build process. Unlike RUN and COPY, they are not executed during the build. They are added as metadata items to the image once it is built.

                  只有稍后,當圖像作為容器運行時,這些元數據字段才會被讀取,并用于啟動容器.

                  It is only later, when the image is run as a container, that these metadata fields are read, and used to start the container.

                  如前所述,入口點是真正運行的,它作為參數列表傳遞給 CMD.它們分開的部分原因是歷史原因.在 Docker 的早期版本中,CMD 是唯一可用的選項,ENTRYPOINT 被固定為 /bin/sh -c.但是由于這種情況,Docker 最終允許 ENTRYPOINT 由用戶定義.

                  As mentioned earlier, the entrypoint is what is really run, and it is passed the CMD as an argument list. The reason they are separate is partly historical. In early versions of Docker, CMD was the only available option, and ENTRYPOINT was fixed as being /bin/sh -c. But due to situations like this one, Docker eventually allowed ENTRYPOINT to be defined by the user.

                  這篇關于如何通過 dockerfile 在 ENTRYPOINT 之前執行 shell 命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                    <tbody id='4K5UK'></tbody>
                  <legend id='4K5UK'><style id='4K5UK'><dir id='4K5UK'><q id='4K5UK'></q></dir></style></legend>

                  <tfoot id='4K5UK'></tfoot>
                • <i id='4K5UK'><tr id='4K5UK'><dt id='4K5UK'><q id='4K5UK'><span id='4K5UK'><b id='4K5UK'><form id='4K5UK'><ins id='4K5UK'></ins><ul id='4K5UK'></ul><sub id='4K5UK'></sub></form><legend id='4K5UK'></legend><bdo id='4K5UK'><pre id='4K5UK'><center id='4K5UK'></center></pre></bdo></b><th id='4K5UK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4K5UK'><tfoot id='4K5UK'></tfoot><dl id='4K5UK'><fieldset id='4K5UK'></fieldset></dl></div>

                    <small id='4K5UK'></small><noframes id='4K5UK'>

                          <bdo id='4K5UK'></bdo><ul id='4K5UK'></ul>
                            主站蜘蛛池模板: 国产精品久久国产精品 | 性欧美精品一区二区三区在线播放 | 亚洲一区二区久久 | 成人在线一区二区 | 亚洲永久在线 | 一级免费毛片 | 在线看片国产精品 | 丁香久久 | 日韩欧美在线播放 | 一区二区三区视频在线观看 | 国产精品s色 | 97起碰| 亚洲国产福利视频 | 一区二区三区四区在线 | 国产日韩中文字幕 | 中国大陆高清aⅴ毛片 | 天天草天天爱 | 国产综合精品一区二区三区 | 日本高清aⅴ毛片免费 | 亚洲午夜视频在线观看 | 欧美伊人久久久久久久久影院 | av网站在线免费观看 | 亚洲在线观看视频 | 91在线一区二区三区 | 九九av| 亚洲人的av | 欧美激情一区二区 | 亚洲狠狠爱 | 国产一区二区三区四区五区加勒比 | 成人在线不卡 | 国产精品久久国产精品久久 | 国产精品成人一区二区三区夜夜夜 | 日韩欧美视频网站 | 老司机狠狠爱 | 性大毛片视频 | 91xxx在线观看| 久久久久一区二区三区四区 | 国产日韩久久 | 新91视频网| 亚洲日韩中文字幕一区 | 国产探花在线精品一区二区 |