-2

I am running docker. I like to use an rhel7 image. The rhel7 image does not have certain package that I need. Let say app XYZ. I would like to include XYZ to the RHEL7 image. How would I do this ?
Do I startup rhel7 container, attach to the container, and download the XYZ app to the running container? Do I download to my local machine and somehow have the container points the local machine ? I will appreciate any example.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
tadpole
  • 1,209
  • 7
  • 19
  • 28
  • You use a [Dockerfile](https://docs.docker.com/engine/reference/builder/) based on the RHEL7 image to create a *new* image that has the packages you need. You'll find lots of examples of building container images online; e.g. [here](https://devopscube.com/build-docker-image/). – larsks Apr 08 '23 at 17:26

1 Answers1

0

Before explaining to you how this works this is a great read about: What are Docker image "layers"?

First, you will need to get inside your running container and install the package you need which is:

yum install XYZ -y

Once the package is installed you can exit from the container with exit in shell

Now you can create a new image from this docker container which we just exited:

docker commit container_name/id rhelWithMyCustomPackage(XYZ)

And done. now this new image rhelWithMyCustomPackage contains your Package which can run after spawning is new container using this image.

To transfer this image say a different Docker host you can use a platform like dockerhub which can maintain docker images for you.

If you read the article I shared above it speaks about these docker images being a read-only entity. This means if suppose you want to recreate this image from the start your Dockerfile will look like this:

FROM rhel7
RUN yum install XYZ

Then you again build this image:

docker build -t rhelWithMyCustomPackage .

And start a new container.

Hope I have explained everything in a crisp and understandable manner. Thanks.

Suchandra T
  • 569
  • 4
  • 8
  • 1
    You should almost never use `docker commit`. Imagine there's some security issue in the base RHEL layer and you need to recreate the image, but it's been a year since you built it; will you remember the exact set of commands you ran to create the image the first time? – David Maze Apr 08 '23 at 22:44