Docker镜像中安装ffmpeg报 E: Some index files failed to download. They have been ignored, or old ones used

背景

公司有一个项目以docker进行部署,项目中增加了一个视频转码的功能,采用的是ffmpeg,所以必须要在docker镜像中安装fmpeg这个软件,但是直接在基础镜像中直接安装软件报软件不存在,所以必须要更换源,经过测试形成最终的Dockerfile如下:

FROM tomcat:7.0.76-jre8
MAINTAINER bettysboy "[email protected]"

#1设置时区
ENV JAVA_OPTS -server -Xms512M -Xmx2048M -Duser.timezone="Asia/Shanghai"

#2配置服务器参数
COPY server.xml $CATALINA_HOME/conf/server.xml
COPY web.xml $CATALINA_HOME/conf/web.xml

#3拷贝程序包到服务器
COPY qyly.war $CATALINA_HOME/webapps/webapp.war

#4删除Tomcat中的Root项目
RUN rm -rf $CATALINA_HOME/webapps/ROOT

#5更换apt源为阿里云的源基础镜像源中没有ffmpeg不能安装
COPY sources.list $CATALINA_HOME/
RUN cat $CATALINA_HOME/sources.list >> /etc/apt/sources.list

#6更新源
RUN apt-get update

#7安装ffmpeg
RUN apt-get -y --force-yes install yasm ffmpeg
EXPOSE 8080

5、6、7步骤就是更新源与安装软件的所有命令在此处也贴一下sources.list

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
#deb http://ftp.cn.debian.org/debian/ wheezy main 

此处注意步骤5中命令是将新的sources.list的内容追加到/etc/apt/sources.list文件末尾。

经过5、6、7这三个步骤就可以在镜像中成功安装ffmpeg了。

先不要高兴的太早,这是2018年初的版本,当时这样是完全没有问题的,最近重新部署的docker build的时候就出问题了。

Docker镜像中安装ffmpeg报 E: Some index files failed to download. They have been ignored, or old ones used_第1张图片

解决方案

上图的报错可以分为两个:

1、NO_PUBKEY 

解决方案是加入如下命令

RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32

后面替换为报错中缺少的KEY即可解决。

2、Some index files failed to download. They have been ignored, or old ones used  instead.       

这个报错是最麻烦的,在网上看了好多文章比如更换其他源之类的好多方法依然报错,最终在一个英文文章里面找到了几行命令成功解决,直接上最终的Dockerfile:

FROM tomcat:7.0.76-jre8
MAINTAINER bettysboy "[email protected]"

#1设置时区
ENV JAVA_OPTS -server -Xms512M -Xmx2048M -Duser.timezone="Asia/Shanghai"

#2配置服务器参数
COPY server.xml $CATALINA_HOME/conf/server.xml
COPY web.xml $CATALINA_HOME/conf/web.xml

#3拷贝程序包到服务器
COPY qyly.war $CATALINA_HOME/webapps/webapp.war

#4删除Tomcat中的Root项目
RUN rm -rf $CATALINA_HOME/webapps/ROOT
COPY sources.list $CATALINA_HOME/

#5解决NO_PUBKEY 
RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32
RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 40976EAF437D05B5
RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com EF0F382A1A7B6500


#6更换源
RUN cat $CATALINA_HOME/sources.list >> /etc/apt/sources.list
RUN echo "deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list
# As suggested by a user, for some people this line works instead of the first one. Use whichever works for your case
# RUN echo "deb [check-valid-until=no] http://archive.debian.org/debian jessie main" > /etc/apt/sources.list.d/jessie.list
RUN sed -i '/deb http:\/\/deb.debian.org\/debian jessie-updates main/d' /etc/apt/sources.list

#7更新源
RUN apt-get -o Acquire::Check-Valid-Until=false update

#8安装ffmpeg
RUN apt-get -y --force-yes install yasm ffmpeg
EXPOSE 8080

               

你可能感兴趣的:(Docker)