MySQL Docker Image on Apple Silicon stuck in Entrypoint Script - mysql

I'm trying to get the official mysql docker image to run on apple silicon.
It does compose and boot up, but it only has 1 log entry and does not do anything else afterwards:
2021-08-04 14:39:12+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.35-1debian10 started.
My docker-compose file looks like this:
database:
platform: linux/amd64 // I also tried linux/x86_64
image: mysql:5.7.35
ports:
- 3306:3306
volumes:
- ./mysql/create_dbs.sql:/docker-entrypoint-initdb.d/create_dbs.sql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=cars
- MYSQL_USER=cars
- MYSQL_PASSWORD=cars
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
Is there something else that needs to be done in order to get it working?

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

Docker-compose up -d - Database is uninitialized (but they are Init.)

I am having the problem starting up Mysql Container in Docker.
Mysql goes up and than it is constantly in restart mode.
The Error message what I got is:
[ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
You need to specify one of the following:
- MYSQL_ROOT_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD
[Note] [Entrypoint]: Switching to dedicated user 'mysql'
[Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
However, 2 of 3 vars are initialized
My docker-compose.yaml configration for Mysql is:
mysql:
build: ./.docker/mysql
restart: unless-stopped
environment:
- MYSQL_USER=app
- MYSQL_PASSWORD=123456
- MYSQL_DATABASE=app
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_ALLOW_EMPTY_PASSWORD=true
volumes:
- ./.docker/mysql/data:/var/lib/mysql
networks:
- app
ports:
- "3306:3306"
For those who think that this Post is duplicate.
I have before this post research other posts (stackoverflow), but it doesnt help me (maybe cos I am using the newest Docker version Docker Engine => v20.10.8 and those Posts are from 2016)
Docker-compose: Database is uninitialized
docker, MYSQL_ROOT_PASSWORD do not work
What did I do until now
read MySql Documentation about Env vars
try solutions from Docker-compose: Database is uninitialized and docker, MYSQL_ROOT_PASSWORD do not work
try to remove my existing mysql container and create new one with docker-compose up -d

Mysql refuses Connection to Adminer on Docker

I know this is a duplicate of this, but since that was never answered, I am re-posting this question.
I am trying to build a basic connection of php-apache and mysql containers.
docker-compose.yml
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
# Exposing the ports doesn't help either
# ports:
# - 3306:3306
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Dockerfile
FROM php:7.2-apache
RUN docker-php-ext-install mysqli
I run a simple docker-compose up command, and access Adminer on localhost:8080.
However, despite using the default login details, i.e
server: db
username: root
password: example
I get the error SQLSTATE[HY000] [2002] Connection refused.
Screenshot:
I think the issue might be some configuration issue on my local machine, because I couldn't use docker based LAMP stacks made by other people too.
Any help is greatly appreciated,
Thank You!
Turns out Patience was the answer.
If I wait long enough(around 4.5 minutes), the mysql container lets out a small log detail.
db_1 | 2021-03-09T08:21:03.882088Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
After that the login in works.
Note: There is a similar line that is logged, but that is regarding port 0, this is 3306. Attempting a failure immediately after that fails.
One must wait for the line with port 3306.
If any of you can give me feedback or advice on how I could make my mysql container initialize faster,
I'd greatly appreciate it.

Docker-compose api and database configuration

I have a problem with connecting Api with MySQL database running in containers. I have Dockerfile for Golang Api:
FROM golang:latest
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
WORKDIR /app/bin
EXPOSE 8080
RUN go run ./../cmd/web/
I usually connect with database in the application using database/sql:
dsn = "user1:pass#tcp(wpmysql:3306)/wp?parseTime=true"
db, err := sql.Open("mysql", dsn)
My docker-compose.yml:
version: '3'
services:
db:
image: mysql:5.7
container_name: ${MYSQL_CONTAINER_NAME}
ports:
- 3306:3306
command: --init-file /usr/src/app/init.sql
volumes:
- ./init.sql:/usr/src/app/init.sql
environment:
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASS}
- MYSQL_DATABASE=${MYSQL_DB}
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
networks:
- fullstack
web:
container_name: wpapi
build: .
ports:
- 8080:8080
restart: on-failure
volumes:
- .:/usr/src/app/
depends_on:
- db
networks:
- fullstack
networks:
fullstack:
driver: bridge
In the same directory as docker-compose.yml is file .env:
DB_PASSWORD=pass
MYSQL_PORT=3306
MYSQL_USER=user1
MYSQL_PASS=pass
MYSQL_DB=wp
MYSQL_CONTAINER_NAME=wpmysql
After call commends:
$ docker-compose up -d db
$ docker-compose build web
I get error ERROR main.go:46: dial tcp: lookup wpmysql on 37.8.214.2:53: no such host. List of containers looks like:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fbaf67df5bf 2778fcda2046 "/bin/sh -c 'go run …" 14 seconds ago Up 13 seconds 8080/tcp mystifying_shannon
7f6c76cc9c4f mysql:5.7 "docker-entrypoint.s…" 40 minutes ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp wpmysql
Moreover when I try to connect in application by dsn = "user1:pass#tcp(localhost:3306)/wp?parseTime=true" or dsn = "root:pass#tcp(localhost:3306)/wp?parseTime=true" I get another error:
dial tcp 127.0.0.1:3306: connect: connection refused although I can go into container (docker exec -it wpmysql bash -l) and sign in with root and user1 credentials
In your docker file you have:
RUN go run ./../cmd/web/
This will attempt to build AND run your executable during the build process. The network fullstack is not available at this time. I think you probably meant to use:
CMD go run ../cmd/web/
This will set the default command run when you start (i.e. docker-compose up) the container to go run ../cmd/web/. Even better would be:
RUN go build ../cmd/web/
CMD ../cmd/web/web
This will build your application as part of the process of building the container and then set the executable produced as the default command. The benefit of doing this is that compile errors become apparent when you build the image (and it means the application is not built every time you start the container).