Skip to content

Instantly share code, notes, and snippets.

@yokomotod
Created March 13, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokomotod/1bca509e2b9bdcbfae9a16e7c8a9ec51 to your computer and use it in GitHub Desktop.
Save yokomotod/1bca509e2b9bdcbfae9a16e7c8a9ec51 to your computer and use it in GitHub Desktop.
MeCab multi-stage Dockerfile
FROM buildpack-deps:buster AS builder
WORKDIR /usr/src
RUN set -x \
# mecab
&& cd /usr/src \
&& curl -L -O -J "https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE" \
&& tar xzf mecab-0.996.tar.gz \
&& cd mecab-0.996 \
&& ./configure --enable-utf8-only --with-charset=utf8 \
&& make -j $(getconf _NPROCESSORS_ONLN) \
&& make install \
# resolve "error while loading shared libraries: libmecab.so.2: cannot open shared object file: No such file or directory"
&& ldconfig \
# mecab-ipadic
&& cd /usr/src \
&& curl -L -O -J "https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7MWVlSDBCSXZMTXM" \
&& tar xzf mecab-ipadic-2.7.0-20070801.tar.gz \
&& cd mecab-ipadic-2.7.0-20070801 \
&& ./configure --with-charset=utf8 \
&& make -j $(getconf _NPROCESSORS_ONLN) \
&& make install
FROM debian:buster-20210311-slim
COPY --from=builder /usr/local/lib/libmecab.* /usr/local/lib/
COPY --from=builder /usr/local/bin/mecab /usr/local/bin/
COPY --from=builder /usr/local/libexec/mecab /usr/local/libexec/mecab
COPY --from=builder /usr/local/include/mecab.h /usr/local/include/mecab.h
COPY --from=builder /usr/local/bin/mecab-config /usr/local/bin/
COPY --from=builder /usr/local/etc/mecabrc /usr/local/etc/mecabrc
COPY --from=builder /usr/local/lib/mecab/dic/ipadic /usr/local/lib/mecab/dic/ipadic
# resolve "error while loading shared libraries: libmecab.so.2: cannot open shared object file: No such file or directory"
RUN ldconfig
FROM alpine:3.13.2 AS builder
WORKDIR /usr/src
RUN set -x \
&& apk --no-cache add ca-certificates curl build-base \
# mecab
&& cd /usr/src \
&& curl -L -O -J "https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE" \
&& tar xzf mecab-0.996.tar.gz \
&& cd mecab-0.996 \
&& ./configure --enable-utf8-only --with-charset=utf8 \
&& make -j $(getconf _NPROCESSORS_ONLN) \
&& make install \
# mecab-ipadic
&& cd /usr/src \
&& curl -L -O -J "https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7MWVlSDBCSXZMTXM" \
&& tar xzf mecab-ipadic-2.7.0-20070801.tar.gz \
&& cd mecab-ipadic-2.7.0-20070801 \
&& ./configure --with-charset=utf8 \
&& make -j $(getconf _NPROCESSORS_ONLN) \
&& make install
FROM alpine:3.13.2
RUN apk --no-cache add libstdc++
COPY --from=builder /usr/local/lib/libmecab.* /usr/local/lib/
COPY --from=builder /usr/local/bin/mecab /usr/local/bin/
COPY --from=builder /usr/local/libexec/mecab /usr/local/libexec/mecab
COPY --from=builder /usr/local/include/mecab.h /usr/local/include/mecab.h
COPY --from=builder /usr/local/bin/mecab-config /usr/local/bin/
COPY --from=builder /usr/local/etc/mecabrc /usr/local/etc/mecabrc
COPY --from=builder /usr/local/lib/mecab/dic/ipadic /usr/local/lib/mecab/dic/ipadic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment