Dockerized-Golang-Postgres-Mysql-API icon indicating copy to clipboard operation
Dockerized-Golang-Postgres-Mysql-API copied to clipboard

Can not connect to database

Open adiatma85 opened this issue 3 years ago • 1 comments

Hello @victorsteven , first, I like to say thank you about the tutorial that you write here

I have some kind of problem when use this repository as reference, when I run docker-compose up the app can not run and have error messages like this image

In docker-compose.yml, the configuration is like this

fullstack-mysql:
    image: mysql:5.7
    container_name: full_db_mysql
    ports: 
      - 3306:3306
    environment: 
      - MYSQL_ROOT_HOST=${DB_HOST} 
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=${DB_NAME}
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
    volumes:
      - database_mysql:/var/lib/mysql
    networks:
      - fullstack

(It's sync with .env file) I can not figure out why I found error while running docker-compose, but I can assure that mysql container is running

Any one have a lead why this is happen? Thanks in advance

adiatma85 avatar Apr 17 '22 06:04 adiatma85

Somehow, it's resolved itself.

I kinda somehow figured what happen, maybe it's because I forgot do run docker-compose up --build

The container kinda piled up with another container. So to make sure it doesn't conflict with another container, what I am doing is:

  • Make sure that there is separate container
  • If there is not exist, run docker-compose up with --build flag

adiatma85 avatar Apr 26 '22 12:04 adiatma85