How create new docker from existing docker contain?

Hi!

I successfully created docker ctonainer with name “my_first_container” like this:

FROM postgres:9.6.24

ENV POSTGRES_HOST_AUTH_METHOD=trus
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=some_pass

WORKDIR /Downloads

COPY /plv8_v.2.x ./Downloads

RUN dpkg -i Downloads/gcc-10-base_10-20200411-0ubuntu1_amd64.deb
RUN dpkg -i Downloads/libgcc-s1_10-20200411-0ubuntu1_amd64.deb
RUN dpkg -i Downloads/plv8-96_2.1.0-2_amd64.deb
RUN dpkg -i Downloads/v8_3.14.5.10-26_amd64.deb
COPY /postgresql /usr/share/postgresql/9.6/extension/
FROM postgres:9.6.24


ENV POSTGRES_HOST_AUTH_METHOD=trust
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=my_pass

# Create folder Downloads in Docker
WORKDIR /Downloads

COPY /plv8_v.2.x ./Downloads

RUN dpkg -i Downloads/gcc-10-base_10-20200411-0ubuntu1_amd64.deb
RUN dpkg -i Downloads/libgcc-s1_10-20200411-0ubuntu1_amd64.deb
RUN dpkg -i Downloads/plv8-96_2.1.0-2_amd64.deb
RUN dpkg -i Downloads/v8_3.14.5.10-26_amd64.deb


COPY /postgresql /usr/share/postgresql/9.6/extension/

Nice.
In this container has PostgreSQl db with 10 tables. Every tables has 10 rows.

Now I work this container about 1 day.
And now every 10 tables has 100 rows.

OK.

Now I want to create another docker container “my_second_container” base on my existing “my_first_container” .

It must contain 10 tables with 100 rows in every table.
Is it possible?

You could just copy the database over.

This a Dockerfile to create an image (not a container) for a postgres version that reached end of life on November, 11th 2021 (see: versioning policy). I am not sure why you have a multi-stage build, without actually leveraging the multi-stage build.

Are you looking to create an initial state when creating the image?
Or are you looking to re-use the state of a container in another container?

Though, why don’t you use the official images. They execute ddl/dml and bash scripts mapped into a specific container path, the first time the container is created. It provides a much easier, cleaner and reproducible approach for creating a deterministic initial database state.

I’m looking to re-use the state of a container in another container

Do you have an example?

No example, you can just use docker cp to copy /var/lib/pgsql. If you have it mapped to a local directory you can copy it from there.