I started a CockroachDB container with the following:
docker run -d --name=node1 --hostname=node1 \
--network=db -p 26257:26257 -p 8080:8080 \
-v "${PWD}/sql:/cockroach/sql" \
-v "${PWD}/cockroach-data/node1:/cockroach/cockroach-data" \
cockroachdb/cockroach:v2.0.1 start --insecure
The /sql
directory has init.sql
, which is a SQL script I want the database to run, this is the command I'm trying to run:
docker exec node1 \
"/cockroach/cockroach sql --insecure < /cockroach/sql/init.sql"
And this is the error I'm getting:
OCI runtime exec failed: exec failed: container_linux.go:348:
starting container process caused
"exec: \"/cockroach/cockroach sql --insecure < /cockroach/sql/init.sql\":
stat /cockroach/cockroach sql --insecure < /cockroach/sql/init.sql:
no such file or directory": unknown
However, if I docker exec -ti node1 /bin/bash
and run the same command manually, it works.
How can I run cockroach sql --insecure < [my SQL script]
from outside the container?