1. <small id='CZF5g'></small><noframes id='CZF5g'>

          <bdo id='CZF5g'></bdo><ul id='CZF5g'></ul>
        <tfoot id='CZF5g'></tfoot>

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

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

        在 Dockerfile 中设置别名不起作用:找不到命令

        时间:2023-09-10

      2. <legend id='BtPSY'><style id='BtPSY'><dir id='BtPSY'><q id='BtPSY'></q></dir></style></legend>

          <tfoot id='BtPSY'></tfoot>
            • <bdo id='BtPSY'></bdo><ul id='BtPSY'></ul>

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

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

                  本文介绍了在 Dockerfile 中设置别名不起作用:找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的 Dockerfile 中有以下内容:

                  I have the following in my Dockerfile:

                  ...
                  USER $user
                  
                  # Set default python version to 3
                  RUN alias python=python3
                  RUN alias pip=pip3
                  
                  WORKDIR /app
                  
                  # Install local dependencies
                  RUN pip install --requirement requirements.txt --user
                  

                  构建图像时,我得到以下信息:

                  When building the image, I get the following:

                   Step 13/22 : RUN alias pip=pip3
                   ---> Running in dc48c9c84c88
                  Removing intermediate container dc48c9c84c88
                   ---> 6c7757ea2724
                  Step 14/22 : RUN pip install --requirement requirements.txt --user
                   ---> Running in b829d6875998
                  /bin/sh: pip: command not found
                  

                  如果我在它上面设置了别名,为什么 pip 无法识别?

                  Why is pip not recognized if I set an alias right on top of it?

                  Ps:我不想使用 .bashrc 来加载别名.

                  Ps: I do not want to use .bashrc for loading aliases.

                  推荐答案

                  问题是别名只存在于镜像中的那个中间层.请尝试以下操作:

                  The problem is that the alias only exists for that intermediate layer in the image. Try the following:

                  FROM ubuntu
                  
                  RUN apt-get update && apt-get install python3-pip -y
                  
                  RUN alias python=python3
                  

                  在这里测试:

                  ❰mm92400❙~/sample❱✔≻ docker build . -t testimage
                  ...
                  Successfully tagged testimage:latest
                  
                  ❰mm92400❙~/sample❱✔≻ docker run -it testimage bash
                  root@78e4f3400ef4:/# python
                  bash: python: command not found
                  root@78e4f3400ef4:/#
                  

                  这是因为每层都启动了一个新的 bash 会话,所以别名会在后面的层中丢失.

                  This is because a new bash session is started for each layer, so the alias will be lost in the following layers.

                  为了保持稳定的别名,您可以像 python 在其 官方图片:

                  To keep a stable alias, you can use a symlink as python does in their official image:

                  FROM ubuntu
                  
                  RUN apt-get update && apt-get install python3-pip -y 
                  
                  # as a quick note, for a proper install of python, you would
                  # use a python base image or follow a more official install of python,
                  # changing this to RUN cd /usr/local/bin 
                  # this just replicates your issue quickly 
                  RUN cd "$(dirname $(which python3))" 
                      && ln -s idle3 idle 
                      && ln -s pydoc3 pydoc 
                      && ln -s python3 python  # this will properly alias your python
                      && ln -s python3-config python-config
                  
                  RUN python -m pip install -r requirements.txt
                  

                  注意使用 python3-pip 包来捆绑 pip.调用 pip 时,最好使用 python -m pip 语法,因为它可以确保您调用的 pip 是与您的 python 安装相关的一个:

                  Note the use of the python3-pip package to bundle pip. When calling pip, it's best to use the python -m pip syntax, as it ensures that the pip you are calling is the one tied to your installation of python:

                  python -m pip install -r requirements.txt
                  

                  这篇关于在 Dockerfile 中设置别名不起作用:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用在 docker 镜像或新容器中不断变化的 p 下一篇:docker CMD 中的命令替换

                  相关文章

                  最新文章

                • <small id='YqkyT'></small><noframes id='YqkyT'>

                    <tfoot id='YqkyT'></tfoot>

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