dockerfile 构建PHP镜像时zlib1g zlib1g-dev死活安装不成功怎么办?
我的dockerfile这是样的(先不管多RUN的问题,咱们先让它能构建成功再来缩减run):
FROM php:7.3.7-fpm
MAINTAINER ealson <huangwh2013@gmail.com>
# Timezone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
# 官方版本默认安装扩展:
# Core, ctype, curl
# date, dom
# fileinfo, filter, ftp
# hash
# iconv
# json
# libxml
# mbstring, mysqlnd
# openssl
# pcre, PDO, pdo_sqlite, Phar, posix
# readline, Reflection, session, SimpleXML, sodium, SPL, sqlite3, standard
# tokenizer
# xml, xmlreader, xmlwriter
# zlib
# 更新为国内镜像
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak \
&& echo 'deb http://mirrors.163.com/debian/ stretch main non-free contrib' > /etc/apt/sources.list \
&& echo 'deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib' >> /etc/apt/sources.list \
&& echo 'deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list \
&& apt-get update
# bcmath, calendar, exif, gettext, sockets, dba,
# mysqli, pcntl, pdo_mysql, shmop, sysvmsg, sysvsem, sysvshm 扩展
RUN docker-php-ext-install -j$(nproc) bcmath calendar exif gettext sockets dba mysqli pcntl pdo_mysql shmop sysvmsg sysvsem sysvshm
# GD 扩展
RUN apt-get install -y --no-install-recommends zlib1g zlib1g-dev libz-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# imagick 扩展
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get install -y --no-install-recommends libmagickwand-dev \
&& rm -r /var/lib/apt/lists/* \
&& pecl install imagick-3.4.4 \
&& docker-php-ext-enable imagick
# mcrypt 扩展
RUN apt-get install -y --no-install-recommends libmcrypt-dev \
&& rm -r /var/lib/apt/lists/* \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt
# Memcached 扩展
RUN apt-get install -y --no-install-recommends libmemcached-dev \
&& rm -r /var/lib/apt/lists/* \
&& pecl install memcached-3.1.3 \
&& docker-php-ext-enable memcached
# redis 扩展
RUN pecl install redis-5.0.0 && docker-php-ext-enable redis
# opcache 扩展
#RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
# xdebug 扩展
#RUN pecl install xdebug-2.7.2 && docker-php-ext-enable xdebug
# swoole 扩展
RUN pecl install swoole-4.4.0 && docker-php-ext-enable swoole
问题出在安GD扩展库时,
报了如下错:
The following packages have unmet dependencies:
zlib1g-dev : Depends: zlib1g (= 1:1.2.8.dfsg-5) but 1:1.2.11.dfsg-1 is to be installed
E: Unable to correct problems, you have held broken packages.
于是把 zlib1g
加入到安装的原码中,但是还是这样,无论如何 也装不上。如何解决?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找我公司的运维大佬帮忙了,错误原因就是:基础镜像是比较干净的一个系统,要不你就换一个基础镜像,没有考虑兼容性问题,导致很多依赖都是要指定版本的,所以有些依赖装不上,指定版本就可以了,我把解决方案贴出来,希望能帮到有同样问题的人。
先执行apt update和upgrade试试
鞭尸了,不要替换镜像,用官方自带镜像就可以的