问题
I'm dockerizing an adonisjs + mysql application. I created a docker-compose and Dockerfile and everything was working just fine, but I wanted to move all those files instead a dedicated directory. Now docker containers are being built and everything starts but I just cannot connect to my MySQL docker.
When I try to connect it always says "Access denied for user 'homestead'@'172.30.0.1' (using password: YES)". The fun fact is that it always puts that 172.30.0.1 it wasn't like this before and it always tries to connect to that host even when I specifically say to connect to localhost.
This is my docker-compose.yml
version: '3'
services:
mysql:
container_name: "${APP_NAME}-mysql"
build: ./mysql
ports:
- "${DB_PORT}:3306"
volumes:
- mysqldata:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
networks:
- api-network
api:
container_name: "${APP_NAME}-api"
build:
context: ../.
dockerfile: ./deploy/api/Dockerfile
volumes:
- ../.:/app
environment:
- HOST=0.0.0.0 # listen on all interfaces
- SERVER_ENV=development
ports:
- "${PORT}:80" # matches actual listener message
depends_on:
- mysql
networks:
- api-network
networks:
api-network:
volumes:
mysqldata:
driver: "local"
This is the Dockerfile
for Mysql
FROM mysql:5.7
COPY custom.cnf /etc/mysql/conf.d/custom.cnf
CMD ["mysqld"]
EXPOSE 3306
This is my custom.cnf
[mysqld]
open-files-limit = 24000
key_buffer_size = 16M
max_allowed_packet = 1000M
thread_stack = 192K
thread_cache_size = 8
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
innodb_fast_shutdown = 1
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_per_table = 1
innodb_buffer_pool_size = 1G # The most important variable here
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 4
innodb_use_native_aio = 0
This is the API Dockerfile
:
FROM node:12.18.2-alpine3.9
MAINTAINER Dan Rusnac <dan@genuino.world>
ENV HOME=/app
RUN mkdir /app
COPY . $HOME
COPY package.json $HOME
WORKDIR $HOME
RUN npm i -g @adonisjs/cli && npm install
EXPOSE 80
CMD ["npm", "start"]
This is the output of docker ps
:
dan@dan-Nitro-AN515-54:~/Documents/Tests/testProject$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4457681caf98 deploy_api "docker-entrypoint.s…" 15 hours ago Up 2 seconds 0.0.0.0:80->80/tcp testProject-api
6348bef9fc22 deploy_mysql "docker-entrypoint.s…" 15 hours ago Up 2 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp testProject-mysql
My .env
HOST=127.0.0.1
PORT=80
NODE_ENV=development
APP_URL=http://${HOST}:${PORT}
APP_NAME=testProject
CACHE_VIEWS=false
APP_KEY=
SESSION_DRIVER=cookie
HASH_DRIVER=bcrypt
DB_CONNECTION=mysql
DB_HOST=172.17.0.1
DB_PORT=3306
DB_USER=homestead
DB_PASSWORD=Secret1234
DB_DATABASE=homestead
DB_ROOT_PASSWORD=password
来源:https://stackoverflow.com/questions/62837140/cant-connect-to-dockerized-mysql