I have a problem with Mysql Docker which exits when I run my docker-compose up command.
Here is my docker-compose.yml file :
version: "2"
services:
web:
build: ./app
links:
- "db-mongo:db-mongo"
- "db-mysql:db-mysql"
ports:
- "443:3000"
volumes:
- "./app:/src"
- "/src/.sass-cache"
- "/src/node_modules"
- "/src/lib"
db-mongo:
build: ./mongo
ports:
- "27017:27017"
volumes:
- "./mongo/db:/data"
db-mysql:
image: mysql
ports:
- "3306:3306"
volumes:
- "./mysql/db:/var/lib/mysql"
- "./mysql/log:/var/log/mysql"
- "./mysql/conf.d:/etc/mysql/conf.d"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: testt
Folders ./mysql/db and ./mysql/log are empty.
When I run docker-compose up, here the output :
db-mysql_1 | Initializing database
server_db-mysql_1 exited with code 1
When I run docker ps -a :
0a5a7a643f18 mysql "docker-entrypoint.sh" 8 minutes ago Exited (1) 7 minutes ago server_db-mysql_1
The strange thing is if I run docker run -d --name=new-mysql -p 3306:3306 -v /var/www/server/mysql/db:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password mysql it works...
And here the output of docker logs 97c -f:
Initializing database
Database initialized
MySQL init process in progress...
Warning: Unable to load '/usr/share/zoneinfo/Factory' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/posix/Factory' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/right/Factory' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
MySQL init process done. Ready for start up.
Why does my docker-compose can't keep alive my mysql docker ? I must missing something... Help ! Thanks
EDIT : It appears it is my conf.d folder which is making some problems, because when I remove volume - "./mysql/conf.d:/etc/mysql/conf.d", server_db-mysql keeps alive.
Here is the mysql/conf.d/my.cnf file content :
[mysqld]
general_log_file = /var/log/mysql/mysql.log
general_log = 1
Why does that file is crashing the mysql ?
It's a permission issue when mounting /var/log/mysql in your custom config file.
Please reference this issue #docker-mysql-146 for the solution:
The owner and group of the /var/log/mysql directory has to be as expected by mysql. Ensure that, execute:
docker exec mysql chown mysql:root /var/log/mysql
Related
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
When I try to set up a cluster with docker swarm I receive this error:
$ docker logs 6ea0f7290cb0
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
2020-11-30 10:46:08+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
What is weird because if I use the docker-compose tool, everything works well.
To replicate this problem follow the steps below.
Create a .env file:
DB_NAME=nest
DB_USERNAME=nest
DB_PASSWORD=nest
DB_ROOT_PASSWORD=nest
Create a docker-compose.yml file:
version: '3.8'
services:
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
If I use the command docker-compose up -d, I can check that everything works well with the docker-compose ps command:
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------
db-debug_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
If I use the command docker stack deploy -c docker-compose.yml db, I can check that the database is not started with the command docker service ls:
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ux1p4k6vwiyh db_db replicated 0/1 mariadb:latest
docker-compose and docker stack deploy have a number of differences in how they parse the compose.yml file. One of them being that the latter does not automatically process a .env files. (reference)
As such you need to explicitly reference it:
services:
db:
image: mariadb
env_file: .env
I am using Portainer agent for deployment on my Swarm cluster and the .env file method doesn't works there.
https://www.portainer.io/blog/using-env-files-in-stacks-with-portainer. Seems like they have some bug in their app.
https://github.com/portainer/portainer/issues/6701
unable to use this method therefore.
I use gitlab runners in docker.
It uses our own php image and mysql:5.7 image. It worked before, but now we can see this error when CI job is started:
Running with gitlab-runner 10.4.0 (857480b6)
on gitlab-runner-2 (00929f5e)
Using Docker executor with image registry.blahblah.work/infra/docker-base/php ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image mysql:5.7 ID=sha256:f008d8ff927dc527c5a57251b45cead7c9259c16a6a93c144f397eaafc103d36 for mysql service...
Waiting for services to be up and running...
*** WARNING: Service runner-00929f5e-project-4-concurrent-0-mysql-0 probably didn't start properly.
Error response from daemon: Cannot link to a non running container: /runner-00929f5e-project-4-concurrent-0-mysql-0 AS /runner-00929f5e-project-4-concurrent-0-mysql-0-wait-for-service/runner-00929f5e-project-4-concurrent-0-mysql-0
2018-02-13T08:49:03.752410664Z
2018-02-13T08:49:03.752468595Z ERROR: mysqld failed while attempting to check config
2018-02-13T08:49:03.752476292Z command was: "mysqld --verbose --help"
2018-02-13T08:49:03.752481759Z
2018-02-13T08:49:03.752486693Z mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
2018-02-13T08:49:03.752491885Z mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Variables are set:
variables:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: password
What should I do to debug and fix this issue?
you need to change your docker compose file, you should add privileged: true mine looks like :
mysql:
build: ./DockerFiles/Mysql
ports:
- ${LOCAL_PHP_IP}:${MYSQL_PORT}:3306
privileged: true
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- /opt/mysql_data:/var/lib/mysql
I am currently beginning experiments with docker-compse. I've created a minimal Flask + MySQL webservice which works perfectly fine without Docker. Now I would like to see how I can make deployment easy with Docker.
My docker-compose.yml looks like this:
version: '3'
services:
web:
build: .
command: app.py
ports:
- "8082:8082"
volumes:
- .:/code
links:
- db
hostname: myappserver
environment:
- MYSQL_ROOT_PASSWORD=p#ssw0rd123
- MYSQL_DATABASE=flask_db
- MYSQL_HOST=db
- MYSQL_PORT=3306
db:
image: mysql
ports:
- "3307:3306"
environment:
- MYSQL_ROOT_PASSWORD=p#ssw0rd123
- MYSQL_DATABASE=flask_db
- MYSQL_HOST=mysqlserver
When I run sudo docker-compose up --build I get
web_1 | sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1146 (42S02): Table 'performance_schema.session_variables' doesn't exist [SQL: "SHOW VARIABLES LIKE 'sql_mode'"]
db_1 | 2017-07-21T22:27:26.553761Z 3 [Note] Aborted connection 3 to db: 'flask_db' user: 'root' host: '172.18.0.3' (Got an error reading communication packets)
What is the problem and how do I fix it?
(The complete project is here: https://github.com/MartinThoma/flask_mysql_dockerized - it's really tiny)
No duplicate of
1: I know if this was on my machine, that I could fix it with mysql_upgrade -u root -p --force and /etc/init.d/mysql start. But the point of using docker compose is to make it really simple to start a web service. One command. If I have to tell the user to login into the container, run those commands, restart the other container.. then I could simply ask him to install it on the main system / run docker containers manually.
So here is what I did to fix it, where I hope that this is possible to be done less manually:
Start the containers:
# docker-comopse up
Find the container ID of the mysql image:
# docker container ls
Enter the container
# sudo docker exec -it 4f7d3f0763ad bash
Upgrade
# mysql_upgrade -u root -p --force
Exit the container, then restart
# docker-compose up
Initialize the database:
# cd /docker-entrypoint-initdb.d/
# mysql -h localhost -u root -p
mysql> source flask_db.sql;
You need to add database to your mysql service:
volumes:
- ./flask_db.sql:/docker-entrypoint-initdb.d/flask_db.sql
Tip: It is recommended to use smaller images so that your image has only required basic components and free from extra non-essential stuff.
I'm having a baffling time with docker-compose and mysql. When I try to start my mysql container with docker-compose, I get an uninformative mkdir error. My Dockerfile and docker-compose.yml don't even seem to contain a mkdir command for mysql.
Here is configuration:
docker-compose.yml
db:
build: docker/mysql
volumes:
- ./database:/var/lib/mysql
environment:
- MYSQL_DATABASE=xxxx
- MYSQL_USER=xxxx
- MYSQL_PASSWORD=xxxx
- MYSQL_ROOT_PASSWORD=xxxx
privileged: true
hostname: "docker.mysql"
Dockerfile
FROM mysql:5.6
MAINTAINER "ABC" <developers#abc.com>
ADD my.cnf /etc/mysql/my.cnf
RUN usermod -u 1000 mysql
RUN usermod -G staff mysql
RUN chown mysql /var/run/mysqld
EXPOSE 3306
my.cnf pastebin
http://pastebin.com/iVSGxhGV
sudo docker --version
Docker version 1.10.0, build 590d5108
This is a docker setup built by my team mates, so I am not sure what the priviledged:true line is doing, but when I remove it, everything appears to work.
with privileged:true
sudo docker-compose up db
Creating appname_db_1
Attaching to appname_db_1
db_1 | mkdir: cannot create directory '': No such file or directory
appname_db_1 exited with code 1
Once privileged: true is removed, it seems to work.
Does anyone know why this might be?