How to use mysql from within another Docker container?
I've got a laravel project that uses a mysql database, it's hosted on bitbucket and we're wanting to use their pipelines feature. The actual pipeline seems simple enough, it's testing my bitbucket-pipelines.yml file that's the difficult part. I read that you should use Docker to spin up some containers of your app and mysql, then run the "script" portion of your pipelines config on your app container. I've got this docker compose file
version: "3.7"
services:
app:
container_name: app
image: php:8.1-fpm
working_dir: /app
volumes:
- ./app:/app
depends_on:
- mysql
tty: true
mysql:
image: "mysql:5.7"
platform: "linux/amd64"
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
volumes:
- mysqldata:/var/lib/mysql/
tty: true
volumes:
mysqldata:
driver: local
I can create those containers with docker compose up and they work. The problem is I open a terminal to my app container and run the pipeline config commands, but when it gets to the phpunit tests at the end where it needs to use mysqladmin, it can't find it. And when I'm in the app terminal and type mysql --version it says command mysql not found. This is the error message I'm seeing "RuntimeException: Command mysqladmin -uroot create 'tests' returned non-zero return code 127. Output: sh: 1: mysqladmin: not found."
I know the containers are supposed to be networked by default by docker compose, but maybe I'm not understanding the purpose of networking. How can I run my phpunit tests while giving them access to mysql?
Please or to participate in this conversation.