给定一个带有 SQL 插入的文件:
INSERT INTO countries (id, country_code, name)
VALUES
(1, 'AF', 'Afghanistan'),
(2, 'AL', 'Albania');
我想通过在docker run
运行 postgres 的容器上使用命令来运行该文件。
我试过这个:
docker run -e domain="192.168.99.100" pg /bin/bash -c "psql -d whiteboard_api -a -f inserts_into_countries_table.sql"
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
你可以看到我的图像是 pg:
capistrano:whiteboard_v2 jzollars$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b500bec9210 bbb "/usr/bin/supervisord" 4 weeks ago Up 4 weeks 0.0.0.0:80->80/tcp distracted_raman
c1e88f2695f5 wh "/usr/bin/supervisord" 4 weeks ago Up 4 weeks 0.0.0.0:3000->3000/tcp high_einstein
7e383e99bdc3 pg "/usr/lib/postgresql/" 4 weeks ago Up 4 weeks 0.0.0.0:5432->5432/tcp pg_test
如何加载此文件并使用 docker 容器在 docker 容器中运行它docker run
?