Hello,
I’m relatively new to Docker and trying to create a docker file for an old application- just to have a docker backup. The application uses an old Ruby on Rails version and requires an MySQL Server 5.6. Everything should be contained in one image and the main application will be the rails webserver later on.
It works perfectly, if I run the commands directly in linux shell with this base image. But if I want to build the image from my docker file, the mysql service doesn’t start up and the database create command fails (Can’t connect to MySQL server on 127.0.0.1).
But according to the Docker build log the service starts properly. If I connect to the intermediate image and start the mysql server and create the database via shell, it also works properly. I need to have it available both during build (To import a mysql dump- RUN) and later on when starting the container (CMD).
I created a minimal docker file to reproduce the problem. What I am doing wrong?
Thanks,
Dirk
# USE DEBIAN 8 JESSIE BASE IMAGE WITH PRE INSTALLED RUBY 1.9.3
FROM corgibytes/ruby-1.9.3:latest
EXPOSE 80
ARG DEBIAN_FRONTEND=noninteractive
# SETUP OLD DEBIAN ARCHIVE FOR APT AND INSTALL REQUIRED PACKAGES
RUN echo "deb http://archive.debian.org/debian jessie main" > /etc/apt/sources.list
RUN apt update --allow-unauthenticated
RUN apt install lsb-release --assume-yes --allow-unauthenticated
# PREPARE MYSQL SERVER CONFIGURATION, DOWNLOAD MYSQL APT CONFIG
RUN printf '%s\n' 'mysql-apt-config mysql-apt-config/select-server select mysql-5.6' | debconf-set-selections
RUN wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
RUN dpkg -i mysql-apt-config_0.8.9-1_all.deb
# UPDATE APT, INSTALL MYSQL SERVER, START SERVICE
RUN apt update --allow-unauthenticated
RUN apt-get install mysql-community-server --assume-yes --allow-unauthenticated
RUN service mysql start
# CREATE DATABASE IN MYSQL- RESULT IN ERROR
# ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
RUN mysql -u root -e "create database test";
OS: Windows 11 Pro 22H2
Docker version: 24.0.2, build cb74dfc