I will not recommend restoring using docker exec
command, the best way to put dump file in docker-image if it is small, or mount the dump file to /docker-entrypoint-initdb.d
.
So add this to your Dockerfile and you will need to run these command once the container is up,
FROM mariadb
COPY backup.sql.gz /docker-entrypoint-initdb.d
So when you start the container it will automatically populated.
Second thing, you can also use host bind volume.
docker run -v $PWD/backup.sql.gz:/docker-entrypoint-initdb.d/ -it mariadb
Initializing a fresh instance
When a container is started for the first time, a new database with
the specified name will be created and initialized with the provided
configuration variables. Furthermore, it will execute files with
extensions .sh, .sql and .sql.gz
that are found in
/docker-entrypoint-initdb.d
. Files will be executed in alphabetical
order. You can easily populate your mariadb services by mounting a SQL
dump into that directory and provide custom images with contributed
data. SQL files will be imported by default to the database specified
by the MYSQL_DATABASE
variable.
mariadb-dockerhub