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

推荐订阅源

N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
C
Cisco Blogs
博客园 - 叶小钗
P
Privacy International News Feed
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
IT之家
IT之家
博客园 - 聂微东
Know Your Adversary
Know Your Adversary
Help Net Security
Help Net Security
罗磊的独立博客
I
Intezer
S
Schneier on Security
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
MyScale Blog
MyScale Blog
P
Privacy & Cybersecurity Law Blog
T
The Exploit Database - CXSecurity.com
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
H
Heimdal Security Blog
S
Secure Thoughts
Hacker News: Ask HN
Hacker News: Ask HN
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
SecWiki News
SecWiki News
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
T
Threat Research - Cisco Blogs
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

John Bokma's Hacking and Hiking

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