kimhxsong / Inception

0 stars 0 forks source link

[ERROR] Can't start server : Bind on unix socket: No such file or directory #4

Closed kimhxsong closed 2 years ago

kimhxsong commented 2 years ago

문제 상황 : 컨테이너가 mysqld을 실행하면 에러를 반환하고 종료됨

Dockerfile

FROM ubuntu:20.04

RUN apt-get update
RUN apt-get install -y mariadb-server

EXPOSE 3306

LABEL version="1.0"
LABEL description="MariaDB Server"

HEALTHCHECK --start-period=5m \
  CMD mariadb -e 'SELECT @@datadir;' || exit 1

CMD ["mysqld"]

참고: https://mariadb.com/kb/en/creating-a-custom-docker-image/#dockerfile-syntax

Container Statuses

(main)⚡ % docker ps -a                                                              ~/Inception/srcs/mariadb
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS                      PORTS                  NAMES
683b315db4da   test        "mysqld"                 14 seconds ago   Exited (1) 11 seconds ago                          zen_agnesi
...

=> 커맨드 실행 직후 종료

Checking what arguments a local mysqld was run with

bash-3.2$ ps -e | grep mysqld
11959 ??         0:00.04 /bin/sh /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
12127 ??         1:18.54 /opt/homebrew/opt/mysql/bin/mysqld --basedir=/opt/homebrew/opt/mysql --datadir=/opt/homebrew/var/mysql --plugin-dir=/opt/homebrew/opt/mysql/lib/plugin --log-error=SSONGui-MacBookAir.local.err --pid-file=SSONGui-MacBookAir.local.pid
 3686 ttys001    0:00.00 grep mysqld

mysqld options

-b, --basedir=name

-h, --datadir=name

--plugin-dir=name

--log-error[=name]

--pid-file=name

kimhxsong commented 2 years ago

Error

error-log

(main)⚡ % docker run -it test bash                                                                                     ~/Inception/srcs/mariadb
root@e6ab5c6fb394:/#
root@1713c66de6f8:/# mysqld --verbose --help | grep log-error
2022-06-13 13:23:26 0 [Note] Plugin 'FEEDBACK' is disabled.
                      --log-slow-query-log-file, --log-error-file, and
  --log-error[=name]  Log errors to file (instead of stdout).  If file name is
log-error                                                  /var/log/mysql/error.log
root@1713c66de6f8:/# cat /var/log/mysql/error.log
2022-06-13 13:21:00 0 [Note] InnoDB: Using Linux native AIO
2022-06-13 13:21:00 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-06-13 13:21:00 0 [Note] InnoDB: Uses event mutexes
2022-06-13 13:21:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-06-13 13:21:00 0 [Note] InnoDB: Number of pools: 1
2022-06-13 13:21:00 0 [Note] InnoDB: Using generic crc32 instructions
2022-06-13 13:21:00 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-06-13 13:21:00 0 [Note] InnoDB: Completed initialization of buffer pool
2022-06-13 13:21:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-06-13 13:21:00 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2022-06-13 13:21:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-06-13 13:21:00 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-06-13 13:21:00 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-06-13 13:21:00 0 [Note] InnoDB: Waiting for purge to start
2022-06-13 13:21:00 0 [Note] InnoDB: 10.3.34 started; log sequence number 1625443; transaction id 20
2022-06-13 13:21:00 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-06-13 13:21:00 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-06-13 13:21:00 0 [Note] InnoDB: Buffer pool(s) load completed at 220613 13:21:00
2022-06-13 13:21:00 0 [Note] Server socket created on IP: '127.0.0.1'.
2022-06-13 13:21:00 0 [ERROR] Can't start server : Bind on unix socket: No such file or directory
2022-06-13 13:21:00 0 [ERROR] Do you already have another mysqld server running on socket: /run/mysqld/mysqld.sock ?
2022-06-13 13:21:00 0 [ERROR] Aborting
kimhxsong commented 2 years ago

mysql_install_db added

FROM debian:bullseye

RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN apt-get update && \
    apt-get install -y \
    mariadb-client \
    mariadb-server

RUN rm -rf /var/lib/mysql; \
    mkdir -p /var/lib/mysql /var/run/mysqld; \
    chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
    chmod 777 /var/run/mysqld;

RUN mysql_install_db;

CMD ["mariadbd"]