Docker Community Forums

Share and learn in the Docker community.

Running Docker Parent image and Base image on top of parent image


(Amaysh85) #1

I am new in docker world. So I have an existing Dockerfile which somewhat looks like below:

# Base image

# Install dependencies
RUN zypper --gpg-auto-import-keys ref -s && \
    zypper -n install git net-tools libnuma1

# Create temp user 
RUN useradd -ms /bin/bash userapp

# Creating all the required folders that is required for installment.
RUN mkdir -p /home/folder1/
RUN mkdir -p /home/folder2/
RUN sudo pip install --upgrade pip

RUN python3

# Many more stuff below this.

So takes time to run which will download many stuff and will execute it.
So the requirement is whenever we add more statements below RUN python3 will unnecessary will execute this python script everytime while building an image. So I would like to split this image into 2 Dockerfiles.

  1. One file you can run only once. This file will have time consuming stuff which can be run only once while building an image.
  2. Second one will be used to add anymore statements which will be added as more layers on top of the existing image.

Because if I run docker build -t "test" . for the current file, it will execute my python script again and again. It’s time consuming and I don’t want to run it again and again.

My questions:

  1. How can split Dockerfile as I mentioned above.?
  2. How can I build an image with 2 image files.?
  3. How can I run these 2 files?

As of now I do :

Build and run: docker build -t "test" . && docker run -it "test"
Just Build : docker build -t "test" .
Just Run : docker run -it "test"