Why are you not placing the backupfile.sql
in dockerfile so it will be restored automatically once the container is up?
FROM mysql
COPY backupfile.sql /docker-entrypoint-initdb.d/
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
mysql-docker-Initializing a fresh instance
OR
docker exec -i mysql-container mysql -uuser -ppassword name_db < backup.sql
Import data.sql MySQL Docker Container
Or with docker-compose
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- $PWD/backup.sql : /docker-entrypoint-initdb.d/backup.sql
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: test