How to execute MySQL command from the host to container running MySQL server?

Mazzy picture Mazzy · Feb 8, 2015 · Viewed 105.3k times · Source

I have followed the instruction in https://registry.hub.docker.com/_/mysql/ to pull an image and running a container in which it runs a MySQL server.

The container is running in the background and I would like to run some commands.

Which is the best way to connect to the container and execute this command from command line?

Thanks.

Answer

Abdullah Jibaly picture Abdullah Jibaly · Feb 8, 2015

You can connect to your mysql container and run your commands using:

docker exec -it mysql bash -l

(Where mysql is the name you gave the container)

Keep in mind that anything you do will not persist to the next time your run a container from the same image.