반응형
mariadb 이미지에 대해 루트 사용자가 아닌 도커 컨테이너를 실행할 수 없습니다.
루트 사용자가 아닌 경우 도커파일을 실행하고 있는 도커 컨테이너는 오류 없이 동작하지만 사용자를 추가하면 다음 오류가 발생합니다.
Initializing database 2019-07-17 21:28:05 0 [Warning] Can't create test file /var/lib/mysql/9e79cb48a1f0.lower-test 2019-07-17 21:28:05 0 [ERROR] mysqld: Can't create/write to file '/var/lib/mysql/aria_log_control' (Errcode: 13 "Permission denied") 2019-07-17 21:28:05 0 [ERROR] mysqld: Got error 'Can't create file' when trying to use aria control file '/var/lib/mysql/aria_log_control' 2019-07-17 21:28:05 0 [ERROR] Plugin 'Aria' init function returned error. 2019-07-17 21:28:05 0 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed. 2019-07-17 21:28:05 0 [ERROR] InnoDB: Operating system error number 13 in a file operation. 2019-07-17 21:28:05 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory. 2019-07-17 21:28:05 0 [ERROR] InnoDB: Operating system error number 13 in a file operation. 2019-07-17 21:28:05 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory. 2019-07-17 21:28:05 0 [ERROR] InnoDB: Cannot open datafile './ibdata1' 2019-07-17 21:28:05 0
[ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
도커 파일
FROM mariadb:10.3.5
RUN apt-get update & apt-get upgrade -y
ENV MYSQL_USER=user1 \
MYSQL_PASSWORD=pass5 \
MYSQL_DATABASE=db \
MYSQL_ROOT_PASSWORD=XXX
RUN useradd -ms /bin/bash newuser
USER newuser
WORKDIR /home/newuser
RUN sudo chown -R newuser:newuser /var/lib/mysql
ADD . /home/newuser
I would like to see the container to run as non root user
Dockerfile의 내용을 살펴보면, 이미 Dockerfile에 루트 없는 사용자가 한 명 추가되어 있는데, 다른 사용자가 필요한 이유는 무엇입니까?
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql
이 단계도 무시당했고
RUN sudo chown -R newuser:newuser /var/lib/mysql
그러나 공식 도커 엔트리 포인트에서 실패하면 DB 초기화 또는 다른 작업을 MySQL 사용자로 실행하므로 새 사용자는 다음 파일을 허용하지 않으므로 권한이 거부됩니다.
이렇게 하려면 도커 엔트리 포인트를 재정의해야 합니다.도커 파일의 일부일 수도 있습니다.여기 코드 형식 Dockerfile이 있습니다.
rm -rf /var/lib/mysql; \
mkdir -p /var/lib/mysql /var/run/mysqld; \
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
chmod 777 /var/run/mysqld; \
언급URL : https://stackoverflow.com/questions/57100157/cannot-run-docker-container-with-non-root-user-for-mariadb-image
반응형
'programing' 카테고리의 다른 글
x**.5와 math.sqrt(x) 중 어느 쪽이 Python에서 더 빠릅니까? (0) | 2022.11.07 |
---|---|
리액트 후크 useState()와 오브젝트 (0) | 2022.11.07 |
Chrome에서 탭이 비활성 상태일 때 setInterval도 작동하도록 하려면 어떻게 해야 합니까? (0) | 2022.11.07 |
브라우저 뷰포트에 상대적인 요소의 맨 위 위치를 가져오려면 어떻게 해야 합니까? (0) | 2022.11.07 |
php.ini: 어떤 거요? (0) | 2022.11.07 |