Điểm:0

socket connection error while building mysql on ubuntu 20.04 docker image

lá cờ in

I am trying to build mysql on ubuntu 20.04 docker image, using dockerfile and configuration bash script to install and configure mysql.

Dockerfile:

FROM ubuntu:20.04

RUN apt-get update -qq && apt-get upgrade -y 

ENV MYSQL_DATABASE: 'test'
ENV MYSQL_USER: 'user1'
ENV MYSQL_PASSWORD: 'xxxxx'
ENV MYSQL_ROOT_PASSWORD: 'root'

COPY . .

RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata

RUN bash configure_mysql.sh

EXPOSE 3306


Configuration Script:

#!/bin/bash

set -e # Exit script immediately on first error.
#set -x # Print commands and their arguments as they are executed.

# Check if MySQL environment is already installed
RUN_ONCE_FLAG=~/.mysql_env_build_time
MYSQL_PASSWORD="root"

if [ -e "$RUN_ONCE_FLAG" ]; then
  echo "MySQL Server environment is already installed."
  exit 0
fi

# Update Ubuntu package index
apt-get update -y -qq


# Installs MySQL 5.5
echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections
apt-get install -y mysql-server

# Configures MySQL
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
sed -i '/\[mysqld\]/a\lower_case_table_names=1' /etc/mysql/my.cnf
echo "MySQL Password set to '${MYSQL_PASSWORD}'. Remember to delete ~/.mysql.passwd" | tee ~/.mysql.passwd; 
mysql -u root -p $MYSQL_PASSWORD -e "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '$MYSQL_PASSWORD'; FLUSH PRIVILEGES;";
service mysql restart
121.122.1
# Installs basic dependencies
echo "installing unzip, git and curl"
apt-get install -y unzip git curl

# Configures prompt color
sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/g' ~/.bashrc
echo 'source ~/.bashrc' >> ~/.bash_profile
source ~/.bash_profile

# Cleaning unneeded packages
apt-get autoremove -y
apt-get clean

# sets "run once" flag
date > $RUN_ONCE_FLAG

However, the configuration script (line no. 29) returns the following error:

Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The command '/bin/sh -c bash configure_mysql.sh' returned a non-zero code: 1

I have tried changing the permission by passing:

chown mysql:mysql /var/run/mysqld/
chmod -R 777 /var/run/mysqld/

but it doesn't work. May I ask, how can i resolver this issue? Looking forward to the suggestions, Thanks!

Đăng câu trả lời

Hầu hết mọi người không hiểu rằng việc đặt nhiều câu hỏi sẽ mở ra cơ hội học hỏi và cải thiện mối quan hệ giữa các cá nhân. Ví dụ, trong các nghiên cứu của Alison, mặc dù mọi người có thể nhớ chính xác có bao nhiêu câu hỏi đã được đặt ra trong các cuộc trò chuyện của họ, nhưng họ không trực giác nhận ra mối liên hệ giữa câu hỏi và sự yêu thích. Qua bốn nghiên cứu, trong đó những người tham gia tự tham gia vào các cuộc trò chuyện hoặc đọc bản ghi lại các cuộc trò chuyện của người khác, mọi người có xu hướng không nhận ra rằng việc đặt câu hỏi sẽ ảnh hưởng—hoặc đã ảnh hưởng—mức độ thân thiện giữa những người đối thoại.