docker - mysql Version - How to update? - mysql

I have no knowledge of docker and its inner workings.
I have a docker image of an application which support has installed on my Linux Desktop.
Current version of mySql when queried through docker prompt is 5.5.6
I updated mysql on my desktop to 5.7.x but still inside docker prompt its showing 5.5.6 ..
Can anyone help me out ?
Output --
dockerdev#localhost:~$ ps -aef | grep mysql
root 31 28 0 14:45 ? 00:00:00 runsv mysql
root 40 34 0 14:45 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe
mysql 471 40 0 14:45 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
dockerdev#localhost:~$ mysql -V
mysql Ver 14.14 Distrib 5.5.62, for debian-linux-gnu (x86_64) using readline 6.3
I run the docker container
docker-compose -f ./application.yml up -d
application.yml
---
myapp:
image: docker.xyz.com/myapp:latest
container_name: myapp
hostname: localhost
ports:
- "80:80" # Apache
- "8000:8000" # Tomcat
- "3306:3306" # Mysql
environment: ....
links: ....
volumes:
# MySQL Data
- /home/kunal/perfios/containers/kubera/perfios/mysql-data:/var/lib/mysql/

Related

Issue with mysql in docker-compose on Mac

I have an issue when trying to use a mysql docker container as part of a docker-compose on my MacBook (2,6 GHz 6-Core Intel Core i7 under Ventura 13.0.1). Here is what my docker-compose.yml file looks like:
version: '3.1'
services:
db:
image: mysql:8.0
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
expose:
- 3306
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u ${MYSQL_USER} --password=${MYSQL_PASSWORD}
interval: 5s
timeout: 5s
retries: 55
restart: unless-stopped
flask:
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./:/var/www/
working_dir: /var/www/
command: python3 app.py
depends_on:
- "db"
restart: unless-stopped
nginx:
image: nginx:1.13.7
container_name: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./static:/var/www/html
ports:
- 80:80
depends_on:
- "flask"
restart: unless-stopped
When trying to run docker-compose up, the mysql container crashes, and I get the following error in the logs:
compose_2023-db-1 | 2023-02-09T22:33:31.523197Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
compose_2023-db-1 | 2023-02-09T22:33:31.523257Z 0 [ERROR] [MY-010119] [Server] Aborting
compose_2023-db-1 | 2023-02-09T22:33:31.523345Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
As visible in my docker-compose.yml, I am not even trying to persist the database in a volume. I have actually tried, both using host file system and a docker volume, with the exact same error each time.
I have tried restarting Docker, my computer, updating Docker, removing all images and containers without success. I also tried several tags for mysql images (namely latest, 7.6 and 8.0) with the same result.
What really bugs me is that this exact same setup used to work fine until earlier today, but I am not able to tell what action caused it to start erroring out every time. More strangely, I can run a mysql container with a similar setup from with the following command:
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=db \
-e MYSQL_USER=myuser \
-e MYSQL_PASSWORD=mypass \
-v $(pwd)/db:/var/lib/mysql \
-p 3306:3306 \
mysql:5.7
It seems that I am not the only one having this type of problem according to this issue on GitHub: https://github.com/docker-library/mysql/issues/757. As suggested on the last comment and since none of the pieces of advice I could find there worked for me, I would be super grateful for any leads on how to fix this.

Can't run MYSQL container using docker-compose

I'm trying to run a MYSQL container for my project using docker-compose.
When I use the following command, everything works fine:
docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:latest
But when I built this docker-compose file:
version: '3.8'
services:
mysql-db:
container_name: mysql-db
image: mysql:latest
environment:
- MYSQL_DATABASE='crm'
- MYSQL_ROOT_PASSWORD='password'
expose:
- "3306"
ports:
- "3306:3306"
The command:
docker-compose up --build
I got this message error:
mysql-db | '/var/lib/mysql/mysql.sock' ->
'/var/run/mysqld/mysqld.sock' mysql-db | Warning: Unable to
load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql-db | Warning: Unable to load
'/usr/share/zoneinfo/leapseconds' as time zone. Skipping it. mysql-db
| Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time
zone. Skipping it. mysql-db | Warning: Unable to load
'/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. mysql-db
| Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time
zone. Skipping it. mysql-db | ERROR 1064 (42000) at line 5: You
have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near '''' at
line 1 mysql-db exited with code 1
I also notice that there is this log right here says that I didn't set the MYSQL_ROOT_PASSWORD although I've already declared that
mysql-db | 2023-01-10T07:29:03.521464Z 6 [Warning] [MY-010453]
[Server] root#localhost is created with an empty password ! Please
consider switching off the --initialize-insecure option.
I'm extremely new to docker so hope you guys can help me.
I tried to reproduce with your compose file locally on my machine and it resulted into same error.
Only solution for this problem currently lies in the link shared by #SelVazi. We would need to build your custom mysql image and then use that to create mysql container.
Here is an example
Create a Dockerfile
I picked mysql image with tag 8 as I am running on Mac M1.
FROM mysql:8.0.31-debian
RUN apt-get update \
&& apt-get install --no-install-recommends -y tzdata \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*
Create Docker Compose file
version: '3.8'
services:
mysql-local:
build: .
image: mysql-local:latest
ports:
- "3307:3307"
container_name: mysql-local
# I am running on Mac M1 Apple Silicon, You might not need it.
platform: linux/x86_64
mysql-db:
container_name: mysql-db
image: mysql-local:latest
depends_on:
- mysql-local
environment:
- MYSQL_DATABASE='crm'
- MYSQL_ROOT_PASSWORD='password'
expose:
- "3306"
ports:
- "3306:3306"
Run compose file
docker-compose -f mysql-compose.yaml up --build

Gitlab-ci running mysql docker and connect it with error ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)

I have see that are other post about these issue, but nothing for the specific case described below.
In my gitlab-ci test pipeline configuration I want to run a mysql docker, and connect to it directly from my runner. But I have difficult to connect to the database.
This is my gitlab-cy-yml test step:
services:
- docker:dind
- mysql:5.7
script:
- apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
- mysql --version
- sleep 20
- docker login -u XXXXXXXX -p XXXXXXXXX
- docker pull mysql:5.7
- docker run --name ticketsDB -d -p 3304:3306 -it -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:5.7
- mysql --protocol=tcp -u root -P 3304
- create database ticketOnline;
- use ticketOnline;
The error is during mysql --protocol=tcp -u root -P 3304 connections:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)
Where am I doing wrong?
There is no need for docker:dind service in you setup.
job:
variables:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_DATABASE: ticketsDB
services:
- mysql:5.7
script:
- apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
- mysql --version
- sleep 20
- mysql --protocol=tcp -u root -P 3304 -h mysql -e "create database ticketOnline; use ticketOnline;"
# -h to specify the host and -e to run a SQL query
Edit:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)
The error occurs because you are trying to connect to localhost instead of the mysql service. By default services have aliases that are created by GitLab by default. Learn More in the docs.
If you need multiple mysql instance you can use multiple aliases like so:
services:
- name: mysql:5.7
alias: mysql-1
- name: mysql:5.7
alias: mysql-2
script:
- mysql mysql --protocol=tcp -u root -P 3304 -h mysql-1 # to connect to the first
- mysql --protocol=tcp -u root -P 3304 -h mysql-2 # to connect to the second.

Correctly using mysql commands in docker-compose?

I am trying to learn docker-compose. I am having trouble running mysql commands through docker compose.
This is my docker-compose file:
version: '3'
services:
mysql:
image: mysql
container_name: mysql
restart: always
env_file: .env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASS
- MYSQL_USER=$MYSQL_USER
- MYSQL_PASSWORD=$MYSQL_PASS
- MYSQL_DB=$MYSQL_DB
volumes:
- db-data:/var/lib/mysql
command: >
mysql -e "CREATE DATABASE \${MYSQL_DB}"
&& mysql -e "GRANT ALL PRIVILEGES ON \${MYSQL_DB}.* TO '\${MYSQL_USER}'#'%'"
&& mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
ports:
- $MYSQL_PORT:3306
volumes:
db-data:
But when I run the docker-compose up --force-recreate --build, I get the mysql usage guide output:
Attaching to mysql
mysql | mysql Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)
mysql | Copyright (c) 2000, 2021, Oracle and/or its affiliates.
mysql |
mysql | Oracle is a registered trademark of Oracle Corporation and/or its
mysql | affiliates. Other names may be trademarks of their respective
mysql | owners.
mysql |
mysql | Usage: mysql [OPTIONS] [database]
mysql | -?, --help Display this help and exit.
mysql | -I, --help Synonym for -?
mysql | --auto-rehash Enable automatic rehashing. One doesn't need to use
mysql | 'rehash' to get table and field completion, but startup
...etc...
Am I using the command: properly to send mysql commands?
I want to suggest a different approach with MySQL:
You can mount another SQL script file that will run at the beginning:
version: '3'
services:
mysql:
image: mysql
container_name: mysql
restart: always
env_file: .env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASS
- MYSQL_USER=$MYSQL_USER
- MYSQL_PASSWORD=$MYSQL_PASS
- MYSQL_DB=$MYSQL_DB
volumes:
- db-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- $MYSQL_PORT:3306
volumes:
db-data:
now create init.sql in your docker-compose.yml directory:
CREATE DATABASE ${MYSQL_DB}
GRANT ALL PRIVILEGES ON ...
You can see it in Initializing a fresh instance.

Docker swarm mode couldn't connect to another container

I created a docker swarm mode cluster and an app deployed. When the app tries to connect to the database, it fails. I able make it work with "docker run" but not in docker swarm mode.
Docker versions
Client:
Version: 1.13.0
API version: 1.25
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.0
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Experimental: false
Error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Docker commands used
sudo docker network create -d overlay cross
sudo docker service create --name database -e MYSQL_ROOT_PASSWORD=admin --replicas 3 -p 3306:3306 --network cross mysql --max_allowed_packet=500M
sudo docker service create --name cross_app --replicas 2 -p 8000:8080 --network cross app1
Ports are open:
sudo docker exec -it 547ed77047c7 nc -v -z database 3306
database (10.0.0.2:3306) open