Vladimir Yanakiev
Vladimir Yanakiev

Reputation: 1300

Base docker image from another docker image

I am using ubuntu20.04. I have a dockerfile. I am taking base image ubuntu20.04. The file is like:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt update && apt install -y tcl;                                             \
   set -ex;                                                                       \
   apt-get update;                                                               \
   apt-get install -y build-essential;                                        \
   apt-get install -y libtbb-dev; 
   ....                                              

I want to have a base image with already installed packages to save time for testing. Instead of using "FROM Ubuntu:20.04". to use something like "FROM MybaseImage". what is the correct way to do it?

Upvotes: 0

Views: 520

Answers (1)

Affes Salem
Affes Salem

Reputation: 1651

you can create a multi staging image using a dockerfile like this:

# Build
FROM alpine as build

WORKDIR /work
COPY / /work
RUN <build-command>

# Test on base image
FROM MybaseImage as test

# You can use the build content into another
COPY --from=build /work /path

# A script where you have a set of commands to be executed
COPY /run.sh /

# You can also create it through the Dockerfile
# RUN echo -e "#!/bin/sh\n\n<test-commands-separated-by-\n> \$@" >/run.sh

RUN chmod +x /run.sh
ENTRYPOINT [ "./run.sh" ]

Upvotes: 1

Related Questions