【问题标题】:docker bash: npm: command not found after building containerdocker bash:npm:构建容器后找不到命令
【发布时间】:2020-08-13 15:50:33
【问题描述】:

我正在使用以下 Dockerfile 构建映像。

但是在构建之后,当我运行 npm install 时,它会显示 bash: npm: command not found

我有2个RUN命令构建2层,第一个基本上是为镜像构建Python环境,包括安装pyodbc驱动和安装必要的包。

第二层是安装node

dockerfile 哪一步出错了?

ARG VARIANT=3
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

ENV PYTHONUNBUFFERED 1

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# [Optional] Update UID/GID if needed
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
    groupmod --gid $USER_GID $USERNAME \
    && usermod --uid $USER_UID --gid $USER_GID $USERNAME \
    && chmod -R $USER_UID:$USER_GID /home/$USERNAME; \
    fi


# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
#
COPY requirements.txt /tmp/pip-tmp/
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get -y update \
    && ACCEPT_EULA=Y apt-get -y install msodbcsql17 \
    && ACCEPT_EULA=Y apt-get -y install mssql-tools \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
    && /bin/bash -c "source ~/.bashrc" \
    && apt-get install -y unixodbc-dev \
    && pip3 install django-mssql-backend \
    && apt-get install -y libgssapi-krb5-2 \
    && pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
    && rm -rf /tmp/pip-tmp

# ** [Optional] Uncomment this section to install additional packages. **
#
RUN apt-get update \
    && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
    #
    # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
    && apt-get -y install git iproute2 procps lsb-release \
    #
    # Install pylint
    #&& pip install pylint \
    #
    # Update Python environment based on requirements.txt
    # && pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
    # && rm -rf /tmp/pip-tmp \
    #
    # Install node for building front-ends
    && apt-get update \
    && apt-get -y install curl gnupg \
    && curl -sL https://deb.nodesource.com/setup_14.x  | bash - \
    && apt-get -y install nodejs \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*


# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=

【问题讨论】:

  • 分享你完整的构建和运行命令
  • 嗨@WSMathias9,完整的构建和运行命令是什么意思?不是上面dockerfile里的那个吗?
  • 用于构建此映像的命令 ex。 docker build -t image:tag .docker run image:tag

标签: docker npm dockerfile


【解决方案1】:

Debian Nodejs 可能是虚假的。使用nodejs官方说明https://github.com/nodesource/distributions/blob/master/README.md#debinstall安装nodejs。

【讨论】:

  • 是的,让我试试这个。
  • 这实际上是我正在做的。 curl -sL https://deb.nodesource.com/setup_14.x | bash - \ && apt-get -y install nodejs 问题依然存在。
  • 你能提供你最新的 Dockerfile 吗?
猜你喜欢
  • 2018-01-17
  • 1970-01-01
  • 2017-03-05
  • 2018-02-18
  • 2018-06-05
  • 2018-08-03
  • 2016-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多