Docker Community Forums

Share and learn in the Docker community.

Is there a way to use a single container across a build for a given dockerfile?

docker

(Amalgovinus) #1

Sorry if this has been asked a million times, I was having some difficulty googling for the answer.

Currently any RUN command in a dockerfile will result in a separate container being created upon build. Is there a way to force all activity during a build to occur in a single container? Or is there a way that a RUN command can target a container that was created previously in the same build?

Thanks!


(Tallandtree) #2

I don’t think so and am curious to your use case.

You could however join RUN command’s to one RUN command:

RUN apt-get clean
RUN apt-get update
RUN apt-get install -y curl

Can be one RUN command like this:

RUN apt-get clean \
  && apt-get update \
  && apt-get install -y curl

See also: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#label