惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
量子位
GbyAI
GbyAI
腾讯CDC
T
Tailwind CSS Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
Docker
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
Jina AI
Jina AI
IT之家
IT之家
Y
Y Combinator Blog

John Bokma's Hacking and Hiking

Setting up a Brother AirPrinter on Ubuntu Failed to verify signature archive-contents.sig in Emacs Aquamacs 3.6 Hangs When Saving An Encrypted File PAR trouble How To Create a Bootable LibreELEC Installation using Mac OS Running pdflatex Using the Alpine Pandoc LaTeX Docker Image A Docker Image for Sass Timezones in Alpine Docker Containers A Tale of Three Docker Images Perl Time::Piece Unicode Issue Giving Docker Desktop for macOS a Second Chance Flashing another TP-Link TL-WDR4300 with OpenWrt firmware Rehousing two tarantulas Getting started with the Perl version of tumblelog on Ubuntu 18.04 LTS A visit to Avonturia De Vogelkelder Flashing a TP-Link TL-WDR4300 with OpenWrt firmware Mounting a VDI File in a Different VirtualBox Guest Wireless Headless Raspberry Pi - John Bokma A Matter of Time - John Bokma Hand coding an RSS 2.0 feed in Python RFC #822 and RFC #3339 dates in Perl RFC #822 and RFC #3339 dates in Python Hand coding an RSS 2.0 feed in Perl Nav Element with no Heading Rewriting CommonMark Nodes in Perl "right" this time
Debugging a Perl Docker container
John Bokma · 2021-06-10 · via John Bokma's Hacking and Hiking

June 9, 2021

In the evening I tried to Dockerize the Perl version of tumblelog. This went very well until I tried to add the CommonMark Perl module which relies on a C library: libcmark.

At this point the Dockerfile was as follows:

# syntax=docker/dockerfile:1
FROM perl:5.34.0-slim AS base

WORKDIR /app

FROM base AS builder
RUN apt-get update \
    && apt-get install -yq build-essential cpanminus libcmark-dev \
    && cpanm URI JSON::XS YAML::XS Path::Tiny CommonMark

FROM base AS run
COPY --from=builder /usr/local /usr/local

COPY tumblelog.pl ./
WORKDIR /data
ENTRYPOINT ["perl", "/app/tumblelog.pl"]

I created the Docker image as follows:

docker build --tag tumblelog/perl -f perl.Dockerfile .

However, when I tried to run this using:

docker run tumblelog/perl

I got the following error message:

Can't load '/usr/local/lib/perl5/site_perl/5.34.0/x86_64-linux-gnu/auto/CommonMa
rk/CommonMark.so' for module CommonMark: libcmark.so.0.28.3: cannot open shared 
object file: No such file or directory at /usr/local/lib/perl5/5.34.0/XSLoader.p
m line 93.
 at /usr/local/lib/perl5/site_perl/5.34.0/x86_64-linux-gnu/CommonMark.pm line 11
.
BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5.34.0/x86_6
4-linux-gnu/CommonMark.pm line 12.
Compilation failed in require at /app/tumblelog.pl line 11.
BEGIN failed--compilation aborted at /app/tumblelog.pl line 11.

Since I used a multi-stage build and cpanm was able to build and test the module something went wrong in the second stage (run). It took me some time to understand that libcmark.so.0.28.3 could not be found, despite the clear message, and that COPY --from=builder /usr/local /usr/local did work as expected.

But where was this required file located? After some reading up on staged builds I learned that I could stop the building process at a certain stage. So I stopped at the builder stage as follows:

docker build --target builder --tag tumblelog/perl -f perl.Dockerfile .

Now I could get an interactive shell (--it option) inside the builder stage and check some things as follows:

docker run -it --entrypoint /bin/sh tumblelog/perl

In the shell I verified that the CommonMark module had been installed in the builder stage correctly using:

perl -MCommonMark -e1

This one-liner tries to load the CommonMark module and executes the program 1. Executing the above resulted in no error at all. So far so good. Next I used find to locate libcmark.so.0.28.3. To be cautious I searched for each file starting with libcmark* as follows:

find / -name 'libcmark*' -print

This resulted in the following list of files:

/var/lib/dpkg/info/libcmark-dev.list
/var/lib/dpkg/info/libcmark0.shlibs
/var/lib/dpkg/info/libcmark0.md5sums
/var/lib/dpkg/info/libcmark0.list
/var/lib/dpkg/info/libcmark-dev.md5sums
/var/lib/dpkg/info/libcmark0.triggers
/usr/share/doc/libcmark-dev
/usr/share/doc/libcmark0
/usr/lib/libcmark.so.0.28.3
/usr/lib/pkgconfig/libcmark.pc
/usr/lib/libcmark.so
/usr/lib/libcmark.a

It turned out that the missing file was located in /usr/lib. Adding another COPY to the run stage fixed the issue at hand. So the next iteration of the Dockerfile became:

# syntax=docker/dockerfile:1
FROM perl:5.34.0-slim AS base

WORKDIR /app

FROM base AS builder
RUN apt-get update \
    && apt-get install -yq build-essential cpanminus libcmark-dev \
    && cpanm URI JSON::XS YAML::XS Path::Tiny CommonMark

FROM base AS run
COPY --from=builder /usr/local /usr/local
COPY --from=builder /usr/lib /usr/lib

COPY tumblelog.pl ./
WORKDIR /data
ENTRYPOINT ["perl", "/app/tumblelog.pl"]

Note that this file is not complete. If you want to Dockerize tumblelog.pl using the above you have to add Try::Tiny to the list of Perl modules.

The resulting image is quite large: 371MB. Especially compared to the Python tumblelog image I created this morning, which uses Alpine and is just 58MB. Tomorrow I want to look into building an Alpine image for the Perl version of tumblelog as well.

Related