MySQL is not working when Docker images started - mysql

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

Related

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

Docker MySQL - cant connect SpringBoot app to MySQL database in docker container using docker-compose

Trying to connect Springboot app dicom_viewer: Imagename: sample with Mysql: Imagename: pb_mysql running in docker container. Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure.
Application.properties file:
#MySQL database connection strings
spring.datasource.url=jdbc:mysql://pb_mysql:3306/test?autoReconnect=true&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=pb
spring.datasource.password=pb#123
#JPA property settings
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
Docker-compose file:
version: '2'
services:
pb_mysql:
container_name: pb_mysql
restart: always
image: mysql/mysql-server:latest
environment:
MYSQL_ROOT_PASSWORD: 'root123' # TODO: Change this
volumes:
- sql-datavolume:/var/lib/mysql
patient_browser:
container_name: patient_browser
restart: always
image: patient_browser
ports:
- 8080:8080
volumes:
- ./dicom_images:/usr/src/app/dicom_images
springboot-image:
container_name: dicom_viewer
restart: always
image: sample
ports:
- 8081:8080
volumes:
sql-datavolume:
networks:
f4:
driver: bridge
Dockerfile:
FROM openjdk:8-jdk-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./target/springboot-image-0.0.1-SNAPSHOT.jar /usr/src/app
COPY . /usr/src/app
EXPOSE 8080
ENTRYPOINT ["java","-jar","springboot-image-0.0.1-SNAPSHOT.jar"]
Database: test, table: pm_of_india
Docker images, docker ps -a
docker-compose up
Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
There are two things to notice,
depends_on
You kept pb_mysql ahead of others in the yaml configuration file. This does not ensure the mysql-server to be up and running ahead of others.
You want to use depends_on, so the depended pb_mysql will be initiated first.
ports
You are using bridged network, so you need to map 3306 to 3306 for mysql-server.
version: '2'
services:
patient_browser:
container_name: patient_browser
restart: always
image: patient_browser
ports:
- 8080:8080
volumes:
- ./dicom_images:/usr/src/app/dicom_images
- 8081:8080
depends_on:
- pb_mysql
springboot-image:
container_name: dicom_viewer
restart: always
image: sample
ports:
- 8081:8080
depends_on: # Let mysql-server start first
- pb_mysql
pb_mysql:
container_name: pb_mysql
ports:
- "3306:3306" # Port mapping.
restart: always
image: mysql/mysql-server:latest
environment:
MYSQL_ROOT_PASSWORD: 'root123' # TODO: Change this
volumes:
- sql-datavolume:/var/lib/mysql
volumes:
sql-datavolume:
networks:
f4:
driver: bridge
I would avoid using restart: always unless I absolutely need it.
The rest looks good to me. Let me know if it is resolved.
You are not referencing your network.
Try adding it to your services i.e.:
services:
pb_mysql:
networks:
- f4
...

How to create spring boot app build including Flyway, Docker and 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.

mysql docker cannot connect from outside container

I've created a docker-compose file for PHP dev but I cannot connect to the DB with sequel pro neither from the APP.
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
ports:
- "80:80"
- "443:443"
networks:
- app-network
#MySQL Service
db:
image: mysql:latest
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
expose:
# Opens port 3306 on the container
- '3306'
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laraveluser
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
everything works OK and no errors are displayed but when I'm trying to connect to the DB in any way it doesn't work docker-compose exec app PHP artisan migrate nor with sequel Pro, what's wrong with my config?
The only way to access the DB is with docker-compose exec db bash
here the full repo
straight from the GitHub repo I have the answer, though I haven't tried yet as I think I'm going to stick with 5.7 for now.
You might need to add --default-auth=mysql_native_password to your command
Mysql:8 uses caching_sha2_password by default https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
#454 (comment)
After digging into your code, I found that you need to update .env.example file
Replace DB_HOST=db on line 10.
You must have missed it, but it is already mentioned in the post that you had referred, under the heading "Step 8 — Modifying Environment Settings and Running the Containers".

Database created but no tables in MySQL Docker

I have a Application run into a tomcat-embededd container and linked with a MySQL database
I have running my container by
docker-compose up --build -d
, the two container is up, i can log in to the application
But , when i put
docker exec -it myapp-mysql bash
and i choise my database with
use dbname;
, i don't see any table into my database
This is my docker-compose
version: "2"
services:
db:
container_name: myapp-mysql
image: mysql:latest
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: XXXXXXXX
MYSQL_DATABASE: XXXXXXX
networks:
app_net:
ipv4_address: A.B.C.D
back-end-java:
container_name: myapp-tomcat
build:
context: .
dockerfile: Dockerfile
restart: always
image: application
ports:
- 8008:8443
links:
- db
networks:
app_net:
ipv4_address: A.B.C.D
networks:
app_net:
driver: bridge
ipam:
driver: default
config:
- subnet: A.B.C.D/24
gateway: A.B.C.D
and this is the Dockerfile
FROM tomcat:8.0.33-jre8
ADD myapp.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
Thank YOU
You are using --build which means you force the recreation of mysql container and since you are not mounting your data volume to the host machine, your data will be wiped out each time you run this command. you can avoid that by mounting mysql data volume to your docker-compose as the following:
version: "2"
services:
db:
container_name: myapp-mysql
image: mysql:latest
restart: always
ports:
- 3306:3306
volumes:
- "./data/mariadb:/var/lib/mysql:rw"
environment:
MYSQL_ROOT_PASSWORD: XXXXXXXX
MYSQL_DATABASE: XXXXXXX
networks:
app_net:
ipv4_address: A.B.C.D