shantanuo
shantanuo

Reputation: 32316

execute sqlite commands within dockerfile

This dockerfile is working correctly. But how do I execute commands within dockerfile?

FROM alpine 
RUN apk add --update sqlite && rm -rf /var/cache/apk/*
RUN apk add --update wget && rm -rf /var/cache/apk/*
RUN wget --no-check-certificate https://cdn.rawgit.com/times/data/master/sunday_times_panama_data.zip
RUN unzip sunday_times_panama_data.zip

But the next part needs to be executed at sqlite prompt. How do I declare this part?

# sqlite commands:
sqlite3 sundayTimesPanamaPapers.sqlite
.mode csv
CREATE TABLE panama(company_url TEXT,company_name TEXT,officer_position_es TEXT,officer_position_en TEXT,officer_name TEXT,inc_date TEXT,dissolved_date TEXT,updated_date TEXT,company_type TEXT,mf_link TEXT);
.import sunday_times_panama_data.csv panama

Upvotes: 3

Views: 2487

Answers (2)

shantanuo
shantanuo

Reputation: 32316

I can save the commands to a file and then execute the file in a dockerfile like this...

ADD sqlite_commands.sql /
RUN sqlite3 panama.sqlite < /sqlite_commands.sql

Upvotes: 1

Alexander Batischev
Alexander Batischev

Reputation: 820

Just feed it the commands using a pipe:

RUN echo '.mode csv\nCREATE TABLE panama(company_url TEXT,company_name TEXT,officer_position_es TEXT,officer_position_en TEXT,officer_name TEXT,inc_date TEXT,dissolved_date TEXT,updated_date TEXT,company_type TEXT,mf_link TEXT);\n.import sunday_times_panama_data.csv panama' | sqlite3 sundayTimesPanamaPapers.sqlite

Upvotes: 0

Related Questions