How to create spring boot app build including Flyway, Docker and Mysql? - mysql

If i try to build spring boot app using gradle without docker implementation, it works.
But when i try to integrate docker with flyway database integration it gives me error.
Error:
application.properties:
Below is my docker-compose.yml file:
version: '3.7'
services:
app:
container_name: dbz_rest_container
image: dbz-rest-image
build:
context: ./
dockerfile: Dockerfile
depends_on:
- db
ports:
- 7000:7000
networks:
- app-mysql
#===================FLYWAY=======================
flyway:
container_name: dbz_rest_flyway_container
image: flyway/flyway:6.3.1
command: -locations=/src/main/resources/db/migration:/flyway/sql -connectRetries=60 migrate
enabled: true
environment:
- FLYWAY_USER=root
- FLYWAY_PASSWORD=root
- FLYWAY_URL=jdbc:mysql://db:5432//dbz
- FLYWAY_SCHEMAS=dbz
volumes:
- ./src/main/resources/db/migration:/flyway/sql
depends_on:
- db
networks:
- app-mysql
#===================MYSQL=======================
db:
container_name: dbz_rest_db_container
image: mysql:latest
ports:
- 5432:3306
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dbz
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
networks:
- app-mysql
networks:
app-mysql:
driver: bridge
Any help would be appreciated.

Related

Node.js service is unable to connect with Mysql using docker composer

I am trying to run 2 Node.js and 2 mysql services with docker composer, both of Node.js services are unable to connect with Mysql services while I was able to login into both Mysql containers with respective credentials.
Node.js service giving the following error:
original: Error: connect ECONNREFUSED 172.22.0.2:3308
enter image description here
I have also successfully connected a PHP script with both of the MySQL services.
My docker-composer file :
version: '3.8'
services:
genreapp:
depends_on:
- genresqldb
build: ./genre
#command: sh -c './wait-for-it.sh -t 0 genresqldb:$DB_PORT_GENRE'
restart: unless-stopped
env_file: ./.env
links:
- genresqldb
volumes:
- ./:/app
ports:
- $NODE_PORT_GENRE:$NODE_PORT_GENRE
environment:
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD_GENRE
- DB_NAME=$DB_NAME_GENRE
- DB_PORT=$DB_PORT_GENRE
- DIALTEC=$DIALTEC
- APP_PORT=$NODE_PORT_GENRE
- HOST=$HOST
- DB_HOST_GENRE=genresqldb
stdin_open: true
tty: true
movieapp:
depends_on:
- moviesqldb
build: ./movie
restart: unless-stopped
env_file: ./.env
links:
- moviesqldb
volumes:
- ./:/app
#command: sh -c './wait-for-it.sh -t 0 moviesqldb:$DB_PORT_MOVIE'
ports:
- $NODE_PORT_MOVIE:$NODE_PORT_MOVIE
environment:
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD_MOVIE
- DB_NAME=$DB_NAME_MOVIE
- DB_PORT=$DB_PORT_MOVIE
- DIALTEC=$DIALTEC
- APP_PORT=$NODE_PORT_MOVIE
- HOST=$HOST
- DB_HOST_GENRE=moviesqldb
stdin_open: true
tty: true
genresqldb:
image: mysql:5
# restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD_GENRE
- MYSQL_DATABASE=$DB_NAME_GENRE
expose:
- $DB_PORT_GENRE
ports:
- $DB_PORT_GENRE:$DB_PORT
volumes:
- db:/var/lib/mysqli
moviesqldb:
image: mysql:5
# restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD_MOVIE
- MYSQL_DATABASE=$DB_NAME_MOVIE
expose:
- $DB_PORT_MOVIE
ports:
- $DB_PORT_MOVIE:$DB_PORT
volumes:
- db:/var/lib/mysqli
volumes:
db:
Just by using Version 3 resolve the issue.

I am not able to create these containers in Oracle Cloud

I receive the following error:
WARNING: The requested image is platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error
#!/bin/bash
version: "3.7"
services:
db:
platform: linux/amd64
image: mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: "Root193782"
MYSQL_DATABASE: "test"
ports:
- "3306:3306"
volumes:
- /data/mysql:/var/lib/mysql
restart: always
networks:
- mysql-network
phpmyadmin:
platform: linux/amd64
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: "Root193782"
ports:
- "8080:80"
volumes:
- /data/php/admin/uploads.ini:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
networks:
- mysql-network
networks:
mysql-network:

MySQL is not working when Docker images started

I try to run local docker environment for WhatsApp api. But when I run docker-compose it writes me that MySQL is not up yet - sleeping. I don't have MySql installed on my PC because I think that docker works smth like VM, so it will download mysql and run it. What can be a problem?
docker-compose.yml
version: '3'
volumes:
whatsappMedia:
driver: local
mysqlData:
driver: local
services:
db:
image: mysql:5.7.35
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
expose:
- "33060"
ports:
- "33060:3306"
volumes:
- mysqlData:/var/lib/mysql
network_mode: bridge
cap_drop:
- MKNOD
wacore:
image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:-2.35.5?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.37.1 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- "db"
network_mode: bridge
links:
- db
cap_drop:
- MKNOD
waweb:
image: docker.whatsapp.biz/web:v${WA_API_VERSION:-2.35.4?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.37.1 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
ports:
- "9090:443"
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
WACORE_HOSTNAME: wacore
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- "db"
- "wacore"
links:
- db
- wacore
network_mode: bridge
cap_drop:
- MKNOD
db.env
WA_DB_ENGINE=MYSQL
WA_DB_HOSTNAME=127.0.0.1
WA_DB_PORT=3306
WA_DB_USERNAME=root
WA_DB_PASSWORD=testpass
WA_DB_CONNECTION_IDLE_TIMEOUT=180000
I edited the docker-compose file, I changed the version from 3 to 3.9, added a default network and deleted network_mode: bridge.
version: '3.9'
volumes:
whatsappMedia:
driver: local
mysqlData:
driver: local
networks:
default:
driver: bridge
services:
db:
image: mysql:5.7.35
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
expose:
- "33060"
ports:
- "33060:3306"
volumes:
- mysqlData:/var/lib/mysql
networks:
- default
cap_drop:
- MKNOD
wacore:
image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- db
cap_drop:
- MKNOD
waweb:
image: docker.whatsapp.biz/web:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
ports:
- "9090:443"
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
WACORE_HOSTNAME: wacore
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- db
- wacore
cap_drop:
- MKNOD

mysql database name and credentials inside docker container not updating

I have a LAMP stack with laravel setup in docker-compose containers,everything seems to be working fine so far. I initially had a test database with the name of homestead setup in docker-compose.yml that was just there for testing now i want to change it to something more meaningful like my project name. let me show you my docker-compose.yml
version: '3'
networks:
laravel:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- 80:80
volumes:
- ./src:/var/www/html:delegated
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: alis
MYSQL_USER: alis
MYSQL_PASSWORD: pass
MYSQL_ROOT_PASSWORD: pass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ./src:/var/www/html:delegated
networks:
- laravel
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
user: laravel
entrypoint: ['composer', '--ignore-platform-reqs']
networks:
- laravel
npm:
image: node:latest
container_name: npm
volumes:
- ./src:/var/www/html
ports:
- 3000:3000
- 3001:3001
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html:delegated
depends_on:
- mysql
working_dir: /var/www/html
user: laravel
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
container_name: phpmyadmin
depends_on:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
the problem is phpmyadmin is still using the old database and credentials , it tried the following solutions
docker-compose down
docker-compose down -v
then
docker-compose up -d
this didnt work.Out of frustration even thought this is probably not the best way to do it, I removed all containers, all images and then ran
docker-compose up -d
to re-install everything from scratch to my surprise phpmyadmin still picks up the old database config.Does anyone know the reason for this behaviour?
Your phpmyadmin service tries to connect as root:secret (MYSQL_ROOT_PASSWORD) while your mysql service defines root:pass (MYSQL_ROOT_PASSWORD) as admin user.
See the available configuration here:
https://hub.docker.com/_/phpmyadmin
https://hub.docker.com/_/mysql

flask can not connect mysql in docker compose

flask can not connect mysql in docker compose
in connect string, I already use db service name as host, still can't connect db
My docker-compose.yml:
services:
api:
build:
context: ./api
dockerfile: Dockerfile
volumes:
- './api:/usr/src/app'
ports:
- 5002:5000
environment:
- FLASK_CONFIG=development
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3307/gaojiesi
- SECRET_KEY=ZQbn05PDeA7v11
depends_on:
- mysql-db
links:
- mysql-db
restart: unless-stopped
mysql-db:
image: mysql:8.0
container_name: mysql-db
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=frikyalong
ports:
- "3307:3306"
volumes:
- ./db/mysql/conf/my.cnf:/etc/my.cnf.d/
- ./db/mysql/logs:/logs
- ./db/mysql/data:/var/lib/mysql
you need to change :
DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3307/gaojiesi
to :
DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3306/gaojiesi
port 3307 in not reachable from inside the container