Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2.1K
Views
Mysql installation for alpine linux in docker

I have still problem with mysql installation on alpine in docker.

I need also openjdk:8u201-jdk-alpine3.9.

My dockerfile:

FROM openjdk:8u201-jdk-alpine3.9
RUN apk update && \
    apk add mysql mysql-client && \
    rm -f /var/cache/apk/* && \
    addgroup mysql mysql && \
    mkdir run/mysqld && \
    touch /var/run/mysqld/mysqld.sock && \
    touch /var/run/mysqld/mysqld.pid && \
    chown -R mysql:mysql /var/run/mysqld/mysqld.sock && \
    chown -R mysql:mysql /var/run/mysqld/mysqld.pid && \
    chmod -R 644 /var/run/mysqld/mysqld.sock && \
    apk add openrc --no-cache

But, in container: - there is no mysql service (only mariadb, but it is probably standard situation for alpine) - there is no any my.cnf file in /etc/mysql directory

When I tried mysql command, I got error:

Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (111)

When I tried mysql -h 127.0.0.1 -P 3306 -u root command, I got error:

Can't connect to MySQL server on '127.0.0.1' (115)

That same for localhost.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

First of all - why do you want to install mysql-server on that specific image? I would suggest using 2 separate containers - one for the mysql database and one for the application you are developing using that openjdk image.

You can simply use this gist https://gist.github.com/karlisabele/d0bebe3d27fc44a57d1db9a9abdff45a to create a setup where your Java application can connect to mysql database using database (the service name) as hostname for mysql server.

See https://hub.docker.com/_/mysql for additional configurations on mysql image (you should define MYSQL user, password, db name etc...)


UPDATE

I updated the gist and added the environment variables necessary for the mysql to work... Replace the qwerty values with your own and you should be able to access the database from your Java application via database:3306 using the username and password provided in the environment variables

The volumes definition at the end of the file tells docker daemon that we want to create a persistent volume somewhere in the host file system and use mysql as an alias. So that when we define the database service volumes we can simply use the mysql:/var/lib/mysql and it will actually mount an obscure folder that docker created on your filesystem. This will allow the mysql database to have persistent state everytime you start the service (because it will mount the data from your host machine) and you don't have to worry about the actual location of the volume

You can see all volumes by running docker volumes ls

over 4 years ago · Santiago Trujillo Report

0

  1. vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]

#skip-networking
  1. restart the mysql container
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!