gpt4 book ai didi

docker - 无法在最终Docker镜像中显示已安装npm的应用程序

转载 作者:行者123 更新时间:2023-12-02 19:58:30 28 4
gpt4 key购买 nike

我已将Vega工具的安装添加到docker-asciidoctor Dockerfile中,并且在运行bats测试时它们就存在,但是在运行镜像时它们不再存在。

我是Docker的新手。

我还尝试了将dir node_modules添加到路径的一些变体,但是没有任何效果。

在所有情况下,Vega工具的安装目录都根本不在镜像中。

我正在添加Vega工具,如下所示:

...
&& npm install --build-from-source -g vega-cli vega vega-lite vega-embed \
&& echo `which vl2vg` \
...

提供以下输出:
...
/usr/bin/vl2png -> /usr/lib/node_modules/vega-lite/bin/vl2png
/usr/bin/vl2svg -> /usr/lib/node_modules/vega-lite/bin/vl2svg
/usr/bin/vl2vg -> /usr/lib/node_modules/vega-lite/bin/vl2vg
/usr/bin/vg2pdf -> /usr/lib/node_modules/vega-cli/bin/vg2pdf
/usr/bin/vg2png -> /usr/lib/node_modules/vega-cli/bin/vg2png
/usr/bin/vg2svg -> /usr/lib/node_modules/vega-cli/bin/vg2svg
...
/usr/bin/vl2vg

就像人们期望的那样。

对其中一种工具的测试如下所示:
@test "vl2vg is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which vl2vg
}

过去了

当执行以下操作时,我希望Vega工具在图像中可用:
docker run -it --entrypoint /bin/sh asciidoctor/docker-asciidoctor
/documents # which vl2vg
which: no vl2vg in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)

给定图像生成的输出,我希望看到 /usr/bin/vl2vg/usr/lib/node_modules不存在。

为了完整起见,这里是Docker文件和采取的步骤:
FROM alpine:3.9

LABEL MAINTAINERS="Guillaume Scheibel <guillaume.scheibel@gmail.com>, Damien DUPORTAL <damien.duportal@gmail.com>"

ARG asciidoctor_version=2.0.9
ARG asciidoctor_confluence_version=0.0.2
ARG asciidoctor_pdf_version=1.5.0.alpha.17
ARG asciidoctor_diagram_version=1.5.16
ARG asciidoctor_epub3_version=1.5.0.alpha.9
ARG asciidoctor_mathematical_version=0.3.0
ARG asciidoctor_revealjs_version=2.0.0

ENV ASCIIDOCTOR_VERSION=${asciidoctor_version} \
ASCIIDOCTOR_CONFLUENCE_VERSION=${asciidoctor_confluence_version} \
ASCIIDOCTOR_PDF_VERSION=${asciidoctor_pdf_version} \
ASCIIDOCTOR_DIAGRAM_VERSION=${asciidoctor_diagram_version} \
ASCIIDOCTOR_EPUB3_VERSION=${asciidoctor_epub3_version} \
ASCIIDOCTOR_MATHEMATICAL_VERSION=${asciidoctor_mathematical_version} \
ASCIIDOCTOR_REVEALJS_VERSION=${asciidoctor_revealjs_version}

# Installing package required for the runtime of
# any of the asciidoctor-* functionnalities
RUN apk add --no-cache \
bash \
curl \
ca-certificates \
findutils \
font-bakoma-ttf \
graphviz \
inotify-tools \
make \
openjdk8-jre \
py2-pillow \
py-setuptools \
python2 \
ruby \
ruby-mathematical \
ttf-liberation \
unzip \
which

RUN addgroup --system appgroup && adduser -S appuser -G appgroup

WORKDIR /data/



# Installing Ruby Gems needed in the image
# including asciidoctor itself
RUN apk add --no-cache --virtual .rubymakedepends \
build-base \
libxml2-dev \
ruby-dev \
&& gem install --no-document \
"asciidoctor:${ASCIIDOCTOR_VERSION}" \
"asciidoctor-confluence:${ASCIIDOCTOR_CONFLUENCE_VERSION}" \
"asciidoctor-diagram:${ASCIIDOCTOR_DIAGRAM_VERSION}" \
"asciidoctor-epub3:${ASCIIDOCTOR_EPUB3_VERSION}" \
"asciidoctor-mathematical:${ASCIIDOCTOR_MATHEMATICAL_VERSION}" \
asciimath \
"asciidoctor-pdf:${ASCIIDOCTOR_PDF_VERSION}" \
"asciidoctor-revealjs:${ASCIIDOCTOR_REVEALJS_VERSION}" \
coderay \
epubcheck:3.0.1 \
haml \
kindlegen:3.0.3 \
pygments.rb \
rake \
rouge \
slim \
thread_safe \
tilt \
&& apk add --update npm \
# && npm -g config set user root \
&& apk --no-cache --virtual .canvas-build-deps add \
build-base \
cairo-dev \
jpeg-dev \
pango-dev \
giflib-dev \
pixman-dev \
pangomm-dev \
libjpeg-turbo-dev \
freetype-dev \
&& apk --no-cache add \
pixman \
cairo \
pango \
giflib \
# && npm -g config set user root \
&& npm config set user 0 \
&& npm config set unsafe-perm true \
&& npm install --build-from-source -g vega-cli vega vega-lite vega-embed \
&& echo `which vl2vg` \
# && apk del .canvas-build-deps \
&& apk del -r --no-cache .rubymakedepends

ENV PATH /data/node_modules/.bin:$PATH
ENV NODE_PATH /data/node_modules/

# Installing Python dependencies for additional
# functionnalities as diagrams or syntax highligthing
RUN apk add --no-cache --virtual .pythonmakedepends \
build-base \
python2-dev \
py2-pip \
&& pip install --upgrade pip \
&& pip install --no-cache-dir \
actdiag \
'blockdiag[pdf]' \
nwdiag \
Pygments \
seqdiag \
&& apk del -r --no-cache .pythonmakedepends

USER appuser

WORKDIR /documents
VOLUME /documents

CMD ["/bin/bash"]

构建命令(从 Makefile提升):
DOCKER_IMAGE_NAME ?= docker-asciidoctor
DOCKERHUB_USERNAME ?= asciidoctor
DOCKER_IMAGE_TEST_TAG ?= $(shell git rev-parse --short HEAD)
build:
docker build \
-t $(DOCKER_IMAGE_NAME_TO_TEST) \
-f Dockerfile \
$(CURDIR)/

测试是:
test:
bats $(CURDIR)/tests/*.bats

其中一项测试是上述测试。

最佳答案

造成这种情况的根本原因是,由于未标记图像,所以我没有使用刚刚构建的图像。

docker tag asciidoctor/docker-asciidoctor:442d4d0 asciidoctor/docker-asciidoctor:latest

然后事情就起作用了。

关于docker - 无法在最终Docker镜像中显示已安装npm的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56138776/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com