개발 기록

Docker Ubuntu-mySQL 서버 생성 기록

ch-yang 2023. 1. 26. 16:39
docker pull mysql:8.0.22

위의 명령어로 mysql 서버를 다운로드 사용하면 간편하긴 한데, 이미지에서 지원하는 명령어가 많이 없다.
(ps, apt, vim 등...)

그래서 공부할 겸해서 ubuntu로 어느정도 기능을 추가한 이미지를 만들어 봐야겠다.

Ubuntu 환경 설정

우분투는 LTS 중 20.04를 사용하겠다.

#ubuntu 기본 이미지 pull
docker pull ubuntu:20.04
docker run -it --name temp ubuntu:20.04 /bin/bash
exit
docker start temp
docker exec -it temp /bin/bash

1. 버전은 그냥 한번 확인

더보기

root@a90403541175:/# uname -a
Linux a90403541175 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@a90403541175:/# cat /etc/issue
Ubuntu 20.04.5 LTS \n \l

root@a90403541175:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

2. 지원하는 명령어 확인

더보기

root@a90403541175:/# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   4112  3404 pts/0    Ss+  06:38   0:00 /bin/bash
root         9  0.0  0.0   4236  3480 pts/1    Ss   06:38   0:00 /bin/bash
root        23  0.0  0.0   5896  2896 pts/1    R+   06:40   0:00 ps -aux
root@a90403541175:/# cd
root@a90403541175:~# ls
root@a90403541175:~# vi temp.txt
bash: vi: command not found
root@a90403541175:~# vim
bash: vim: command not found
root@a90403541175:~# vi
bash: vi: command not found
root@a90403541175:~# vim
bash: vim: command not found
root@a90403541175:~# wget
bash: wget: command not found
root@a90403541175:~# git
bash: git: command not found
root@a90403541175:~# sudo
bash: sudo: command not found
root@a90403541175:~# make
bash: make: command not found
root@a90403541175:~# apt
apt 2.0.9 (amd64)
Usage: apt [options] command

apt is a commandline package manager and provides commands for
searching and managing as well as querying information about packages.
It provides the same functionality as the specialized APT tools,
like apt-get and apt-cache, but enables options more suitable for
interactive use by default.

Most used commands:
  list - list packages based on package names
  search - search in package descriptions
  show - show package details
  install - install packages
  reinstall - reinstall packages
  remove - remove packages
  autoremove - Remove automatically all unused packages
  update - update list of available packages
  upgrade - upgrade the system by installing/upgrading packages
  full-upgrade - upgrade the system by removing/installing/upgrading packages
  edit-sources - edit the source information file
  satisfy - satisfy dependency strings

See apt(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).
                                        This APT has Super Cow Powers.

명령어를 실행해보니 apt가 되니까 따로 dockerfile을 만들어서 할 필요는 없어보인다.
vim 정도만 설치하고 더 진행해보자

3. locale 확인

 locale 을 기본으로 쓰면 나중에 문제 생기는 경우가 많았다. 'en_US.UTF8'로 설정해야겠다.

root@a90403541175:~# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
root@a90403541175:~# locale -a
C
C.UTF-8
POSIX
root@a90403541175:~#

locale 설정해주려고 보니까 locale-gen도 없어서 설치해주려는데 실패했다.
locale-all 은 설치 잘됐다. 다음부터는 그냥 locale-all로 한번에 설치해야겠다.

root@0744b28b1639:/# locale-gen en_US.UTF-8
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
root@0744b28b1639:/# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
root@0744b28b1639:/# locale -a
C
C.UTF-8
POSIX
en_US.utf8
root@0744b28b1639:/# export LANG='en_US.UTF8'
root@0744b28b1639:/# locale
LANG=en_US.UTF8
LANGUAGE=
LC_CTYPE="en_US.UTF8"
LC_NUMERIC="en_US.UTF8"
LC_TIME="en_US.UTF8"
LC_COLLATE="en_US.UTF8"
LC_MONETARY="en_US.UTF8"
LC_MESSAGES="en_US.UTF8"
LC_PAPER="en_US.UTF8"
LC_NAME="en_US.UTF8"
LC_ADDRESS="en_US.UTF8"
LC_TELEPHONE="en_US.UTF8"
LC_MEASUREMENT="en_US.UTF8"
LC_IDENTIFICATION="en_US.UTF8"
LC_ALL=
root@0744b28b1639:/#

locale-gen 도 해줬고 export LANG='en_US.UTF8' 도 해줬는데, export 로만 환경변수를 설정하면 종료 후에 지워진다. 그러면 ~/.bashrc 를수정해주면 되긴하는데 괜히 아름답지 못한 것 같다.

dockerfile로 세팅해야겠다. 이전에 작성했던 dockerfile 살짝 수정해보자

https://ch-yang.tistory.com/11

FROM ubuntu:20.04 
RUN apt-get update 
RUN apt-get upgrade -y
RUN apt-get install -y vim locales locales-all
RUN locale-gen en_US.UTF-8 

#환경변수 설정 
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

locales-gen 없다고 해서 locales 추가해서 빌드했다. 실행 후 locale도 확인해보니 잘 설정되었다.

더보기

PS C:\3.Study\23.0126_docker_mysql> docker run -it --name customMySQL ubuntu:20.04 /bin/bash
root@57d0dc76e36d:/# exit
exit
PS C:\3.Study\23.0126_docker_mysql> docker exec -it customMySQL /bin/bash
Error response from daemon: Container 57d0dc76e36d8b14232651fb96d4b4bea348312e08ffceddab9577af7ea7de19 is not running
PS C:\3.Study\23.0126_docker_mysql> docker start customMySQL
customMySQL
PS C:\3.Study\23.0126_docker_mysql> docker exec -it customMySQL /bin/bash
root@57d0dc76e36d:/# locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
root@57d0dc76e36d:/#

mysql 설치

apt install mysql-server 실행 중 이슈

  1. Timezone 물어보는 것
    1. timedatectl로 설정가능한데 설치할 것 systemd로 설치하고 나서도 다음과 같은 에러가 생겼다.
      System has not been booted with systemd as init system (PID 1). Can't operate.
      리눅스 초기화 프로그램의 차이라고 한다 (SysVinit, Systemd)
      리눅스 SysVinit, Systemd 차이 (tistory.com) 
    2. 심볼릭 링크 파일을 수정하면 될 것 같다.
      리눅스 TimeZone 변경 :: 잡학문구 (tistory.com)  
      > /usr/share/zoneinfo 디렉토리 조차 없다...
      > 그냥 dockerfile timezone 설정 관련 내용이 검색은 되지만 수동으로 해주고 넘어가자.
  2. Cannot stat file /proc/19/fd/14: Permission denied

재설치해보니까 찝찝하게 이미 설치되었다고 한다.
사용은 되는 것 같은데 해결한 내용이 검색이 안된다...
다음에 이어서 해봅시다...

'개발 기록' 카테고리의 다른 글

yum  (0) 2023.04.11
MySQL/MariaDB 쿼리 기록  (0) 2023.04.11
Windows에서 WSL2를 활용한 Docker 사용 관련 기록  (0) 2023.01.20
Hugo 블로그 생성 과정 기록 (with Docsy theme)  (0) 2022.12.22