Mike T
Mike T

Reputation: 492

Docker MySQL no output

Docker for Windows

I have a machine set up with 2 containers. They are both running the standard mysql image. One is set up to be the server, and I am linking to it from the other and attempting to run mysql commands.

Ideally, I would like to be able to do this all through the command prompt so I can call it through Python.

I was able to run a few commands error-free and attempted to place my name into the Username table of myDB.

When I run the command:

docker exec sqlserverClient mysql -uroot -ppassword -e"use myDB" -e"select * from Usernames"

I get back the output:

Warning: Using a password on the command line interface can be insecure

And nothing else.

Where is my table? Even if the insert went wrong, shouldn't I at least see a blank table?

I expected to see something like this:

+------------+-------------+
| firstname  | lastname    |
+------------+-------------+
| First      | Last       |
+------------+-------------+

"docker logs sqlserverClient" doesn't have it. So where did it go?

Upvotes: 2

Views: 1075

Answers (1)

VonC
VonC

Reputation: 1324093

Try with docker exec -it, to have tty and the output

But remember docker exec is for debug only.

The best practice is to have a docker container with:

  • an entrypoint set to sqlserverClient
  • a cmd that you pass in parameter when running a transient container.

That is:

docker run --rm -it sqlimage mysql -uroot -ppassword -e"use myDB" -e"select * from Usernames"

Once the command is executed, the container stopped and is rmeoved.

That means you can have an alias like:

alias drs='docker run --rm -it sqlimage'

And call:

drs mysql -uroot -ppassword -e"use myDB" -e"select * from Usernames"

Upvotes: 3

Related Questions