【问题标题】:Install libmysqlclient-dev along with npm in dockers在 dockers 中安装 libmysqlclient-dev 和 npm
【发布时间】:2023-03-15 00:49:01
【问题描述】:

我在尝试将libmysqlclient-dev 软件包与npm 一起安装时出现错误,由于某种原因在安装libmysqlclient-dev 时它会删除npm

Step 10/26 : RUN apt-get install -y libmysqlclient-dev
 ---> Running in beae8aee9cd4
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  gyp javascript-common libjs-async libjs-inherits libjs-jquery
  libjs-node-uuid libjs-underscore libuv1-dev node-abbrev node-ansi
  node-ansi-color-table node-archy node-async node-balanced-match
  node-block-stream node-brace-expansion node-builtin-modules
  node-combined-stream node-concat-map node-cookie-jar node-delayed-stream
  node-forever-agent node-form-data node-fs.realpath node-fstream
  node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
  node-hosted-git-info node-inflight node-inherits node-ini
  node-is-builtin-module node-isexe node-json-stringify-safe node-lockfile
  node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream
  node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once
  node-osenv node-path-is-absolute node-pseudomap node-qs node-read
  node-read-package-json node-request node-retry node-rimraf node-semver
  node-sha node-slide node-spdx-correct node-spdx-expression-parse
  node-spdx-license-ids node-tar node-tunnel-agent node-underscore
  node-validate-npm-package-license node-which node-wrappy node-yallist
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libssl-dev
Suggested packages:
  libssl-doc
The following packages will be REMOVED:
  libssl1.0-dev node-gyp nodejs-dev npm
The following NEW packages will be installed:
  libmysqlclient-dev libssl-dev
0 upgraded, 2 newly installed, 4 to remove and 133 not upgraded.
Need to get 2,583 kB of archives.
After this operation, 5,175 kB disk space will be freed.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.9 [1,566 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmysqlclient-dev amd64 5.7.34-0ubuntu0.18.04.1 [1,016 kB]
dpkg-preconfigure: unable to re-open stdin: 
Fetched 2,583 kB in 2s (1,412 kB/s)
(Reading database ... 25174 files and directories currently installed.)
Removing npm (3.5.2-0ubuntu4) ...
Removing node-gyp (3.6.2-1ubuntu1) ...
Removing nodejs-dev (8.10.0~dfsg-2ubuntu0.4) ...
Removing libssl1.0-dev:amd64 (1.0.2n-1ubuntu5.6) ...

这给了我以下错误:

Step 14/26 : RUN npm install -g npm@4.1.1
 ---> Running in 18f70438b2ae
/bin/sh: 1: npm: not found
ERROR: Service 'webapp' failed to build: The command '/bin/sh -c npm install -g npm@4.1.1' returned a non-zero code: 127

这是我的 Dockerfile:

RUN apt-get update
RUN apt-get install -y tzdata
RUN apt-get install -y libfontconfig1
RUN apt-get install -y libxrender1
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN apt-get install -y yarn
RUN apt-get install -y mysql-client
RUN apt-get install -y libmysqlclient-dev
RUN apt-get install -y shared-mime-info
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN npm install -g npm@4.1.1
RUN npm install -g yarn

我正在研究 ruby​​ on rails 并且我需要 libmysqlclient-dev 包用于 mysql2 gem

我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails docker npm dockerfile libmysql


    【解决方案1】:

    您需要阅读 Docker 文档中的 Dockerfile best practices for the RUN instruction。 Dockerfile 中的每一行都是一个镜像层,RUN 指令执行命令后的状态并不总是持久化到下一层。

    所以apt-get install -y npm 不会在您运行npm install -g ... 时影响构建,因此您收到错误:npm command not found

    请阅读指南并尝试改用这条RUN 指令。

    RUN apt-get update \
        && apt-get install -y tzdata \
        && apt-get install -y libfontconfig1 \
        && apt-get install -y libxrender1 \
        && apt-get install -y nodejs \
        && apt-get install -y npm \
        && apt-get install -y yarn \
        && apt-get install -y mysql-client \
        && apt-get install -y libmysqlclient-dev \
        && apt-get install -y shared-mime-info \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
        && npm install -g npm@4.1.1 \
        npm install -g yarn
    

    【讨论】:

      【解决方案2】:

      使用 npm 附带的新节点对我有帮助:

        apt-get -qq update && \
        apt-get -qq --no-install-recommends install curl && \
        curl -sL https://deb.nodesource.com/setup_17.x | bash - && \
        apt-get -qq --no-install-recommends install \
          openssl \
          nodejs \
          linux-headers-generic \
          tzdata \
          libmysqlclient-dev
      

      【讨论】:

        猜你喜欢
        • 2016-09-26
        • 2023-03-10
        • 2019-01-20
        • 2017-04-16
        • 2021-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多