Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 515
Mazzy Avatar asked Feb 08 '15 01:02

Mazzy


People also ask

How do I run MySQL in a Docker container?

Here are the steps you can follow to install the Dockerhub MySQL Container: Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.

How do you run a command in a running container?

Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.

How do I connect to the MySQL server using the MySQL command line client with the following command?

Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.


1 Answers

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.

like image 117
Abdullah Jibaly Avatar answered Oct 19 '22 19:10

Abdullah Jibaly