1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dockerfile で一般ユーザーを作成する

1
Posted at

Dockerfile

ENV UNAME=docker
ENV GID=1000
ENV UID=1000

RUN groupadd -g $GID -o $UNAME
RUN useradd -m -u $UID -g $GID -G sudo -o -s /bin/bash $UNAME
RUN echo "$UNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

こんな感じに書いてあげると、一般ユーザーを作成できる。

echo "$UNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

のコマンドによって、sudo もパスワード無しで実行できるようになる

docker-compose

user で id を指定してあげると、ログインユーザーを変更できる。

version: "3.7"
services:
  app:
    ...
    environment:
      GID: 1000
      UID: 1000
    user: "1000:1000"

ちょっとはまったところ

node のイメージだったりだと、UID 1000 ですでに一般ユーザーが用意されている場合がある。
この場合は RUN echo "node ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers としてあげることで、 sudo が使えるようになる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?