Create a Docker Image of a sql file

Hi,

It’s the first time I am working on docker and I am not sure of how I can create a Docker image for a
SQL script.

I believe we have to create a docker file for this although I am not sure of I can make it work.

Appreciate for any quick response.

Thanks in advance

If you’re looking to dockerize a configuration file or script. you may want to look into volumes and configs. Both have their advantages and disadvantages, depending on what you’re trying to do with the script. Have a look at the docs I linked to, and you can make your own decision as to which is most appropriate.

Its not a configuration file. I want to make a docker image for a DML/DDL Sql file. So it can be used in any machine by pulling the image.

Hi :slight_smile:

So you want to create a database image/container, where the sql file is imported, so when a guy pulls the image, he will have a database with content?

is it mysql or ?

Hi Martin,

Exactly. I have a sql file dump for which i am planning to create a docker image. So when anyone pulls that image, he should get the database and data content imported into his local machine.

Yeah i am using mysql for this.

Do you have any solution for it?

Appreciate for your help :slight_smile:

Sorry for the delayed answer, i have been off the grid the whole weekend :slight_smile:

but this should work (havnt tested)

FROM mysql
ADD sqldump.sql /docker-entrypoint-initdb.d/

ENV MYSQL_ROOT_PASSWORD yourpassword

Hi Martin,

Thanks for the reply. Now I am able to create a docker image for my sql script and able to execute it as well. My another requirement is like apart from this image, i have another image of a DDL script which should be executed after image i have created. Is there any way which can be done in a single yml or a docker file?

Both the sql’s will be pointing to same db, port.so i would like to execute on same container.

Depends on how your script works.
If you have 2 images, and you need to have the database up BEFORE you execute the script container, you can checkout https://docs.docker.com/compose/startup-order/

But if its a simple script (depending on what it does) you can add it to the database image

Hi

I am using SAP HANA.So I want to create a database image/container, where the my data file is imported, so when a guy pulls the image, the guy will have a database with content.