Docker:如何保持软件版本一致性

huangapple go评论78阅读模式
英文:

Docker: How to keep consistent versions of softwares

问题

我正在使用基于Python的图像,通常我会执行以下操作:

FROM python:3.10.10-buster

###########################################

升级软件包

###########################################

下载最新的可用软件包列表:

RUN apt-get -y update

升级已安装的软件包:

RUN apt-get -y upgrade


我正在安装一个软件包

RUN apt install s3fs


我担心每次构建图像时都会安装s3fs的新版本,可以如何将s3fs固定在特定版本的Docker图像中?

因为最近我们有一个2年前的Docker图像,当时的s3fs软件包和现在的版本不同。在最新版本中,s3fs软件包的工作方式不如旧版本时那样预期。

所以,如何锁定版本?
英文:

I am using a python based image and generally I do the below

FROM python:3.10.10-buster

###########################################
# Upgrade the packages
###########################################
# Download latest listing of available packages:
RUN apt-get -y update
# Upgrade already installed packages:
RUN apt-get -y upgrade

I am installing a package

RUN apt install s3fs

I am worried by doing the below a newer version of s3fs will get installed every time i build the image

RUN apt-get -y update
RUN apt-get -y upgrade

How can i pin s3fs to a particular version in my docker image

because recently we had a docker image which i 2yrs old and the s3fs package at that time and now have different versions. And in the recent version the s3fs package is not working as intended as it was working with old version.

So how to pip the versions

答案1

得分: 0

有两个主要的选项供您选择:

  1. 您可以直接在apt命令中针对特定版本进行固定。可以通过在本地添加一个文件,然后将其复制到容器中来实现这一点。该文件将如下所示:
Package: s3fs
Pin: version 2.1.1*
Pin-Priority: 1000

您需要根据您想要的版本进行调整。

然后修改您的Dockerfile如下:

FROM python:3.10.10-buster

# 安装s3fs
RUN apt install s3fs=<your version>

# 复制您创建的文件
COPY pinningfile /etc/apt/preferences.d/s3fs

###########################################
# 升级软件包
###########################################
# 下载最新的可用软件包列表:
RUN apt-get -y update
# 升级已安装的软件包:
RUN apt-get -y upgrade
  1. 您可以自己创建一个基础镜像。这样,您可以创建一个包含所有软件包的特定版本的基础镜像,然后相应地用于您的软件。

然后您将拥有两个Dockerfile:

FROM python:3.10.10-buster

###########################################
# 升级软件包
###########################################
# 下载最新的可用软件包列表:
RUN apt-get -y update
# 升级已安装的软件包:
RUN apt-get -y upgrade

# 现在安装s3fs
RUN apt-get -y install s3fs=<fixed Version>

构建镜像,标记它并推送它:

docker build -t my-s3fs-base:latest .
docker push my-s3fs-base:latest

现在您可以将其用作您的软件的基础镜像:

FROM my-s3fs-base:latest

RUN <do whatever you need>
英文:

There are two main options for you:

  1. You pin directly to a version in the apt command. This can be achieved by adding a file locally, that you then copy into the container. The file will look like this:
Package: s3fs
Pin: version 2.1.1*
Pin-Priority: 1000

You need to adjust to the version that you want.

Then modify your dockerfile like follows:

FROM python:3.10.10-buster

# Install s3fs
RUN apt install s3fs=&lt;your version&gt;

# copy the file you created
COPY pinningfile /etc/apt/preferences.d/s3fs

###########################################
# Upgrade the packages
###########################################
# Download latest listing of available packages:
RUN apt-get -y update
# Upgrade already installed packages:
RUN apt-get -y upgrade
  1. You can create a base image yourself. This way you would create a base image with all the packages installed to a specific version and then use that respectively for your software.

You would then have two Dockerfiles:

FROM python:3.10.10-buster

###########################################
# Upgrade the packages
###########################################
# Download latest listing of available packages:
RUN apt-get -y update
# Upgrade already installed packages:
RUN apt-get -y upgrade

# Now install s3fs
RUN apt-get -y install s3fs=&lt;fixed Version&gt;

Build the image, tag it and push it:

docker build -t my-s3fs-base:latest .`
docker push my-s3fs-base:latest

Now you can use that as base image for your software:

FROM my-s3fs-base:latest

RUN &lt;do whatever you need&gt;

huangapple
  • 本文由 发表于 2023年8月9日 11:49:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864450-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定