Discussion:
[docker] Running .sql files on docker volumes
Koushik S
2016-03-07 15:58:11 UTC
Permalink
Hi,

I am trying to run this sql file but somehow it is not getting executed.
Anything wrong with this?

docker run -it -e MYSQL_ROOT_PASSWORD=Password -v $(pwd)/mysql/script:/tmp/ --link auditdata:mysql --rm mysql sh -c 'exec mysql -hmysql -P3306 -uroot -pPassword operations_rw < /tmp/create_table.sql'
Максим Сёмочкин
2016-03-08 05:23:32 UTC
Permalink
The mistake is that you override the command which starts the Docker container. Instead the wrapper script starts the import of your data. But they still have nowhere to import the server while not running.

Instead, you can create your own image based on mysql. Which will start the server and upload the database sql file. See below how to do it.

FROM mysql
ENV MYSQL_ROOT_PASSWORD=root_pwd \
MYSQL_DATABASE=zabbix \
MYSQL_USER=zabbix \
MYSQL_PASSWORD=zabbix
COPY zabbix.sql /docker-entrypoint-initdb.d/zabbix.sql
EXPOSE 3306

Loading...