我正在尝试使用
r-base:4.3.2
作为基础映像为 R 应用程序构建 Docker 映像。当尝试安装 renv::restore()
包时,构建在 systemfonts
期间失败,并出现错误:fatal error: ft2build.h: No such file or directory
。
# Use r-base as the base image
FROM r-base:4.3.2
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libfreetype6 \
libfreetype6-dev \
libharfbuzz-dev \
libfribidi-dev \
libpng-dev \
libtiff5-dev \
libtiff-dev \
libjpeg-dev \
libfontconfig1-dev \
pandoc \
curl \
unzip \
fonts-liberation \
fontconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /usr/src/app
# Install essential R packages
RUN R -e "install.packages(c('renv'), repos = 'https://cloud.r-project.org')"
# Set up renv
RUN mkdir -p renv/cache
ENV RENV_PATHS_CACHE=/usr/src/app/renv/cache
# Copy renv files
COPY renv.lock .
COPY .Rprofile .
COPY renv/activate.R renv/
COPY renv/settings.dcf renv/
# Restore the R environment
RUN R -e "renv::restore()"
COPY . .
# Download and install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf awscliv2.zip aws
RUN aws --version
CMD ["Rscript", "create-dashboard-ecs.R"]
我不断收到此错误:
1432.0 - Installing systemfonts ... FAILED
1432.3 Error: Error installing package 'systemfonts':
1432.3 =======================================
1432.3
1432.3 * installing *source* package 'systemfonts' ...
1432.3 ** package 'systemfonts' successfully unpacked and MD5 sums checked
1432.3 ** using staged installation
1432.3 Found pkg-config cflags and libs!
1432.3 Using PKG_CFLAGS=
1432.3 Using PKG_LIBS=-lfontconfig -lfreetype
1432.3 ** libs
1432.3 using C++ compiler: 'g++ (Debian 13.2.0-13) 13.2.0'
1432.3 rm -f systemfonts.so caches.o cpp11.o dev_metrics.o font_matching.o font_registry.o ft_cache.o string_shape.o font_metrics.o font_fallback.o string_metrics.o emoji.o cache_store.o init.o unix/FontManagerLinux.o
1432.3 g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/usr/src/app/renv/staging/1/cpp11/include' -fPIC -g -O2 -ffile-prefix-map=/build/reproducible-path/r-base-4.3.2=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -mbranch-protection=standard -Wdate-time -D_FORTIFY_SOURCE=2 -c caches.cpp -o caches.o
1432.3 In file included from caches.h:7,
1432.3 from caches.cpp:1:
1432.3 ft_cache.h:9:10: fatal error: ft2build.h: No such file or directory
1432.3 9 | #include <ft2build.h>
1432.3 | ^~~~~~~~~~~~
1432.3 compilation terminated.
1432.3 make: *** [/usr/lib/R/etc/Makeconf:200: caches.o] Error 1
1432.3 ERROR: compilation failed for package 'systemfonts'
1432.3 * removing '/usr/src/app/renv/staging/1/systemfonts'
1432.3 install of package 'systemfonts' failed [error code 1]
1432.3 Traceback (most recent calls last):
1432.3 13: renv::restore()
1432.3 12: renv_restore_run_actions(project, diff, current, lockfile, rebuild)
1432.3 11: renv_install_impl(records)
1432.3 10: renv_install_staged(records)
1432.3 9: renv_install_default(records)
1432.3 8: handler(package, renv_install_package(record))
1432.3 7: renv_install_package(record)
1432.3 6: withCallingHandlers(renv_install_package_impl(record), error = function(e) writef("FAILED"))
1432.3 5: renv_install_package_impl(record)
1432.3 4: r_cmd_install(package, path)
1432.3 3: r_exec_error(package, output, "install", status)
1432.3 2: abort(all)
1432.3 1: stop(fallback)
1432.3 Execution halted
我尝试安装
libfreetype6
和 libfreetype6-dev
我需要安装哪些额外的系统依赖项才能解决缺少的
ft2build.h
错误并成功构建 systemfonts
R 包?
它是我的
renv.lock
中 tidyverse 依赖树的一部分
我能够通过指定
PKG_CONFIG_PATH
来修复它
所以添加这一行最终解决了它
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig