Kalanamith
Kalanamith

Reputation: 20648

How to create a docker image by extending a docker image which was already created

I am creating a docker image as follows stage('Build'){ agent any

        steps{
            script {
              dockerImage = docker.build("my_docker_image", "${MY_ARGS} .")
             }
      }

in a Jenkins file Build stage

I want to create a new Docker image based on the image I created but with additional configurations on the build Stage to use in the test stage.

Is there a way to do it using the dockerImage ?

Upvotes: 0

Views: 65

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

You can reuse images in other dockerfile also for re-usability

Let's assume we have below dockerfile

FROM python:3.6
WORKDIR /app
COPY ./server.py .
CMD ["python", "server.py"]

Now you build it using below

docker build -t production .

Now let's assume you want another testing image which should have telnet installed. Now instead of repeating the dockerfile you can start from the production image which is present locally only

FROM production
RUN apt update && apt install -y telnet

Then build the same using below

docker build -f Dockerfile-testing -t testing .

As you can see there is no duplication of Dockerfile content in this, which is what you probably want

Upvotes: 1

Related Questions