is a running container created by each RUN command during multistage build? I'm new to Docker, sorry if my question sounds dumb.
below is a dockerfile from a textbook:
FROM diamol/base AS build-stage                  
RUN echo 'Building...' &gt; /build.txt              #line 2

FROM diamol/base AS test-stage
COPY --from=build-stage /build.txt /build.txt
RUN echo 'Testing...' &gt;&gt; /build.txt              #line 6

FROM diamol/base
COPY --from=test-stage /build.txt /build.txt
CMD cat /build.txt

and the author says:
The RUN instruction executes a command inside a container during the build, and any output from that command is saved in the image layer.
My question is:
Since the author mentioned RUN instruction executes a command inside a container during the build, does it mean that in the first RUN command in line 2, a contianer is created based on the diamol/base image, and this container modify the content of the files then commit the change back to diamol/base image, then is container is terminated? and same thing happen in line 6,container created to run and then terminate, image gets updated, is my understanding correct?
Yes your understanding is correct. The RUN &lt;commands&gt; command in the Dockerfile is somewhat equivalent to
container = $(docker run base-image) #1
docker exec base-image commands #2 
docker commit $container #3

Since images are static, we'll need a running instance/process to execute our command. this is why a container is created from the base image. #1
After the execution of the command in #2, the changes are committed back #3, which means a new layer is created on top of the previous layers. This layer will contain the changes introduced by the container in (#2).