Build a new docker image from two base images (centos and python)

Viewed 918

I want to build a docker image based on Centos8. Within this image I want to install Python with the version 3.7.7. Such a Python image already exists in dockerhub.

How can I use both base images to build a new docker image?

From python:3.7.7 
# which files and foldes do I have to copy to my new docker image?

From centos:8
LABEL maintainer myself@test.com

If that is not possible it is the best way to build the python version from scratch Link - The problem with this solution is that the docker image is huge.

1 Answers

TL;DR You generally can't have on an image all there is in two images(The reason is explained below)
TL;DR List of solutions:

  1. Use a base image that already is CentOS and has a Python installed, maybe this image.
  2. Start from CentOS image, install Python using package manager in the Dockerfile.
  3. Start from CentOS image, build Python in Dockerfile.
  4. Just use Python in the provided distributions.

Long Answer:
Using FROM imagename is equivalent of downloading a pre-built image and then adding on it the instructions in the current Dockerfile. An image is basically a snapshot of the filesystem.
One of them is the snapshot of a container with probably a Linux distribution in place and Python installed.
The other is snapshot of the filesystem of another Linux distribution with all its stuff in place. You just can't mix them, because the image isn't just Python. It is all Python needs to run beside a working Linux kernel and mixing them together almost certainly breaks them. because they have conflicting files and ways of running them in place.
But you can change one snapshot to make another snapshot off of it, for example you can take image of CentOS and install Python using the package manager, can then take a snapshot off of it and use it as working Docker container.

Related