Chris B.
Chris B.

Reputation: 90249

redirect the output of docker-exec

docker exec is not working for me. If I connect to a running container with docker exec -it mymachine bash and run sh -c 'mysql -u root < /tmp/schema.sql', it works.

If I just run docker exec mymachine sh -c 'mysql -u root < /tmp/schema.sql', it doesn't give any errors, but it doesn't do anything. Nor does it give me any errors if I run docker exec mymachine sh -c 'mysql -u root < /tmp/i_dont_exist.sql'.

How do I fix this?

Upvotes: 0

Views: 1166

Answers (2)

lamirap
lamirap

Reputation: 520

try this -

docker exec mymachine "sh -c 'mysql -u root < /tmp/schema.sql'"

If not then the '<' operator will be picked up by the shell in the host machine and not the container.

Upvotes: 1

kliew
kliew

Reputation: 3183

I suspect that the < operator is trying to grab from your host rather than your container. Try enclosing the entire command in quotations.

Upvotes: 0

Related Questions