Search code examples
dockerdocker-network

How to run mysql command in app docker container?


I use docker compose to run two instances

  • Node backend app container (node_app)
  • Mysql Container (mysql_db)

How can I connect to mysql_db and run command

mysql -uroot -p

directly from node_app


Without a correct configuration, I see error mysql: not found if I run it in node_app container.

I'm wondering if I can try something like SSH from node_app, then SSH to mysql_db and run mysql command. But sounds complex.


Solution

  • You need install mysql tools into your node_app container, into your Dockerfile for instance:

    ...
    RUN apt install mysql-client
    

    If you just want access your database from the cli, you can probably execute mysql from your host machine (where you launch your docker-compose command) with this command: docker exec -it mysql_db mysql