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

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

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固定到特定的版本。

因为最近我们有一个2年前的Docker镜像,当时的s3fs软件包版本与现在不同。而在最新版本中,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=<您的版本>

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

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

2)您可以自己创建一个基础镜像。这样,您可以创建一个包含所有软件包的特定版本的基础镜像,然后相应地将其用于您的软件。

然后,您将拥有两个Dockerfile:

FROM python:3.10.10-buster

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

# 现在安装s3fs
RUN apt-get -y install s3fs=<固定版本>

构建镜像,打标签并推送:

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

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

FROM my-s3fs-base:latest

RUN <进行您需要的操作>
英文:

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.html
匿名

发表评论

匿名网友

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

确定