首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在dockers中安装libmysqlclient-dev和npm

在dockers中安装libmysqlclient-dev和npm
EN

Stack Overflow用户
提问于 2021-06-19 09:02:55
回答 1查看 67关注 0票数 0

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

代码语言:javascript
复制
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) ...

这给了我以下错误:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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的工作,我需要mysql2 gem的libmysqlclient-dev包。

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-19 10:08:05

您将需要从Docker文档中读取Dockerfile best practices for the RUN instruction。Dockerfile文件中的每一行都是一个图像层,RUN指令执行后的状态并不总是保存在下一层上。

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

请阅读本指南,并尝试使用此单一RUN指令。

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68042784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档