0

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.

1 Answer 1

3

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"
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant, thank you. I knew I was doing something stupid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.