I have a Docker container running MariaDB and within the Dockerfile for the image I've copied an SQL file to a location in the container:
FROM mariadb
RUN mkdir /adhoc_scripts
COPY bootup.sql /adhoc_scripts
Once the container has spun up, I'm able to enter a shell within the container and confirm that the sql file does exist in the specified location:
$ docker exec -it my_mariadb_container bash
root@6e3f4b9abe17:/# ls -lt /adhoc_scripts/
total 4
-rw-r--r-- 1 root root 1839 Apr 10 18:35 bootup.sql
However when I exit the container and try to invoke the following command:
docker exec -it my_mariadb_container bash \
mysql mydb -u root -prootpass \
< /adhoc_scripts/bootup.sql
I get this error:
-bash: /adhoc_scripts/bootup.sql: No such file or directory
What am I doing wrong?
EDIT1: I tried changing the permissions of /adhoc-scripts
to 777 as well, but that didn't help.
This is because the <
operator operates on the whole docker exec ...
command instead of the bash mysql ...
part.
The error message is clear: your bash (outside the container) is trying to interpret the /adhoc_scripts/bootup.sql
file.
To solve it, try this:
docker exec -it my_mariadb_container bash -c "mysql mydb -u root -prootpass < /adhoc_scripts/bootup.sql"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.