Hi.
Example
Start a PostgreSQL container
š³ gforghetti:[~/Downloads] $ docker container run -it --detach --name my_db --env POSTGRES_DB=MY_DB --env POSTGRES_USER=my_user --env POSTGRES_PASSWORD=secret postgres:latest
699f1eea11c379b35aa82599522e0053128fbfa41fb72f64dbc00d08cfd5e06e
List the container
š³ gforghetti:[~/Downloads] $ docker container ls --filter name=my_db
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
699f1eea11c3 postgres:latest "docker-entrypoint.sā¦" 11 seconds ago Up 10 seconds 5432/tcp my_db
Create a file with an sql command
š³ gforghetti:[~/Downloads] $ echo 'select version();' > test.sql
Copy the sql fle to the container
š³ gforghetti:[~/Downloads] $ docker container cp test.sql my_db:/
Run the command in the sql file
š³ gforghetti:[~/Downloads] $ docker container exec -it my_db psql --dbname=MY_DB --username my_user -f /test.sql
version
--------------------------------------------------------------------------------
--------------------------------------------------
PostgreSQL 11.2 (Debian 11.2-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gc
c (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
š³ gforghetti:[~/Downloads] $