A
A
AmeRain2017-10-21 17:48:01
MySQL
AmeRain, 2017-10-21 17:48:01

How to access MySQL installed inside Docker container?

I'm trying to access MySql installed inside a Docker container I get an
error Access denied for user 'root'@'172.18.0.5' (using password: YES)
Here's my docker-compose.yml file:

version: '2'
services:
  #  The Application
  app:
    image: app
    working_dir: /var/www
    volumes:
      - /var/www/storage
    env_file: '.env'
    environment:
      - "DB_HOST=database"
      - "REDIS_HOST=cache"

  # The Web Server
  web:
    image: web
    ports:
      - "8000:80"

  # The Database
  database:
    image: mysql:5.7.19
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - MYSQL_DATABASE="dev"
      - MYSQL_USER="root"
      - MYSQL_PASSWORD="root"
      - MYSQL_ROOT_PASSWORD="root"
    ports:
      - "3306:3306"


  # redis
  cache:
    image: redis:3.0-alpine

volumes:
  dbdata:

I build and run everything with the commands:
docker build -t app -f app.dockerfile .
build -t web -f web.dockerfile .
docker-compose -f docker-compose.yml up -d
The project in which the file is located is written in Laravel. OS Windows 10

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
Zlatoslav Desyatnikov, 2017-10-21
@pxz

So you have ports forwarded (3306), connect to localhost:3306.
But if the muscle is already running locally, then change the port in the compose file.
Here you can read how to view forwarded ports:
https://docs.docker.com/engine/reference/commandli...

P
planc, 2017-10-21
@planc

app:
    depends_on:
        - "database"

if you use your own images, then instead of image: you can use build: path to the folder with dockerfile:
docker-compose build to create

S
scor2k, 2017-10-26
@scor2k

First, check access to the database from the host. You wrote above that port 3306 should be available on localhost. If your docker-compose password access works, then look at the `app` service settings, you may not be using the correct connection data there.
Well, for the `app` service, add a parameter

links:
 - "database"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question