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?

Dockerfileの実行ユーザーを変更する

Last updated at Posted at 2024-02-10

Expected

  1. Dockerfileの実行ユーザーをroot -> aliceに変更したい。
  2. aliceでrailsアプリを作成したい(権限をaliceにしたい)

Actual

  • もっと色々あるんだろうけど、最近勉強中のシェルコマンドでやってみた。
FROM ruby:3.0.1

# 環境変数の設定
ENV DOCKER_OPERATION_USER=alice
ENV APPLICATION_NAME=blog

# dockerグループを作成
RUN groupadd docker

# dockerグループに所属するユーザーを作成
RUN useradd -g docker -u 1000 ${DOCKER_OPERATION_USER} -m

# sudo権限付与
RUN usermod -aG sudo ${DOCKER_OPERATION_USER}

# 必要最低限のツールを入れる
RUN apt-get update -qq && apt-get install -y sqlite3 vim

# ユーザーの切り替え
USER ${DOCKER_OPERATION_USER}

# railsをインストール
RUN gem install rails

# アプリケーションディレクトリを作成
RUN mkdir /home/${DOCKER_OPERATION_USER}/${APPLICATION_NAME}

# アプリケーションディレクトリを作業用ディレクトリに設定
WORKDIR /home/${DOCKER_OPERATION_USER}/${APPLICATION_NAME}

# railsアプリ作成(初回のみ)
RUN rails new .
1
0
1

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?