0

I'm trying to dockerize my Laravel app. In my local machine i have Mysql and MongoDB.

I have a script that run mysql restore and mongorestore to restore a production db.

In local environment i don't have problems because mysql and mongodb are installed locally.

Now, i created a docker-compose.yml with the build instructions:

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: .docker/Dockerfile.dev
    image: laravel-docker
    ports:
      - 8080:80
    volumes:
      - /srv/app/vendor
      - .:/srv/app
    links:
      - mariadb
      - redis
  redis:
    image: redis:latest
  mariadb:
    image: mariadb:latest
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_USER=root
  mongo:
    image: mongo

All works fine but i need to run mysql command from app container (that should call mysql command in mariadb container)

0

1 Answer 1

1

Just install a MySQL client in your app container.

Add something like this in your Dockerfile :

apt-get install mysql-client

Then you should be able to connect to your MySql server from your app container using the service name if they belong to the same network :

mysql -u USERNAME -p PASSWORD -h mariadb
Sign up to request clarification or add additional context in comments.

1 Comment

I'm trying this now. I need some time to rebuild the container but its seems the right solution! I think is a bit different for mongo db..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.