当命令指定为CMD a b c时,一切都会按预期工作,而同时使用CMD ["a", "b", "c"]指定相同的命令-会产生意外的结果。
我正在尝试在docker中运行Jupyter(ipython)。我的CMD命令是要启动它。看来,无论我如何指定它-Jupyter都会启动。但是,仅当我将其指定为CMD a b c时,jupyter才能真正正常工作,并且有可能启动内核。
在这种情况下,“新建笔记本”命令有效

    FROM debian:stable
    RUN apt-get update && apt-get install -y wget bzip2
    RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
        bash Miniconda2-latest-Linux-x86_64.sh -b -p /anaconda2
    RUN /anaconda2/bin/conda install jupyter

    #CMD ["/anaconda2/bin/jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--NotebookApp.token=''"]
    CMD /anaconda2/bin/jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --NotebookApp.token=''

    # docker build -t IMAGE_NAME .
    # docker run --rm -it -p 8888:8888 IMAGE_NAME

在这种情况下,“新建笔记本”命令不起作用
    FROM debian:stable
    RUN apt-get update && apt-get install -y wget bzip2
    RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
        bash Miniconda2-latest-Linux-x86_64.sh -b -p /anaconda2
    RUN /anaconda2/bin/conda install jupyter

    CMD ["/anaconda2/bin/jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--NotebookApp.token=''"]
    #CMD /anaconda2/bin/jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --NotebookApp.token=''

    # docker build -t IMAGE_NAME .
    # docker run --rm -it -p 8888:8888 IMAGE_NAME

我对此感到非常困惑,无法想到会有什么不同!

最佳答案

shell form(CMD a b c)使用已解析的字符串调用 shell ,而exec形式(CMD [a, b, c])直接使用指定的参数启动可执行文件。

由于没有以exec形式进行 shell 解析(在这种情况下,它已删除了 shell 形式的空引号),因此最后一个参数应为"--NotebookApp.token="。这以--NotebookApp.token=的形式提供给程序,没有两个撇号。

从手册中:

关于docker - Docker `CMD a b c` VS `CMD [“a”, “b”, “c”]`,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42353048/

10-16 17:41