[英]MySQL Docker container - unable to import file
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: 我有一个运行MariaDB的Docker容器,并且在镜像的Dockerfile中,我已经将一个SQL文件复制到了容器中的某个位置:
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: 一旦容器旋转起来,我就可以在容器内输入一个shell并确认sql文件确实存在于指定位置:
$ 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. EDIT1:我也尝试将
/adhoc-scripts
的权限也更改为777,但这没有帮助。
This is because the <
operator operates on the whole docker exec ...
command instead of the bash mysql ...
part. 这是因为
<
运算符对整个docker exec ...
命令而不是bash mysql ...
部分进行操作。
The error message is clear: your bash (outside the container) is trying to interpret the /adhoc_scripts/bootup.sql
file. 错误消息很明显:您的bash(容器外部)正在尝试解释
/adhoc_scripts/bootup.sql
文件。
To solve it, try this: 要解决它,请尝试以下操作:
docker exec -it my_mariadb_container bash -c "mysql mydb -u root -prootpass < /adhoc_scripts/bootup.sql"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.