In cases such as restoring a database dump, or otherwise wishing to push some information through a pipe from the host, you can use the -i
flag as an argument to docker run
or docker exec
.
E.g., assuming you want to put to a containerized mariadb client a database dump that you have on the host, in a local dump.sql
file, you can perform the following command:
docker exec -i mariadb bash -c 'mariadb "-p$MARIADB_PASSWORD" ' < dump.sql
In general,
docker exec -i container command < file.stdin
Or
docker exec -i container command <<EOF
inline-document-from-host-shell-HEREDOC-syntax
EOF