0
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?

Docker:user 起動した、コンテナをrootでログインする

Last updated at Posted at 2025-05-21

以下のコマンドでDockerコンテナへ入り、操作を行うとします。

# docker exec -it <コンテナ名>
[user@e87140ca08ea batch]$ docker exec -it <コンテナ名> bash
user@e87140ca08ea:/src$

対応方法

docker exec コマンド実行時に、 -u 0 をオプションに追加します。

# docker exec -it -u 0 <コンテナ名>

上記コマンドを実行すると、そのコンテナ内をrootユーザーとして操作が行えるようになります。

root@e87140ca08ea:/src#

理由

-u root ではNGとなります。/etc/passwdにてユーザrootのユーザIDが「0」で作成され、優先されるからです。

0
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
0
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?