LoginSignup
10
2

More than 1 year has passed since last update.

DockerのUbuntuをunminimizeで通常に戻す

Last updated at Posted at 2023-06-26

Linux上での操作手順の確認や「Ubuntuでアレどうやるんだっけ?」みたいなときに、いちいち仮想マシンを用意するのは手間なので、手軽に扱えるDocker上で試してみようとすると、思うように動かないことがあります。

そんな時の解決方法を紹介します。

なお、本記事ではUbuntuイメージを対象としています。CentOS等の他のディストリビューションについては事情も異なるでしょうし扱いません。

DockerのUbuntuは特殊版

Dockerイメージというのは基本的に余計なものを極限まで削ぎ落として軽量化されているものが多く、一般的に中に入ってインタラクティブにあれこれ操作するのには向いていません。

普通のLinuxのような感覚で操作しようと思ったら、下記のような謎のメッセージが表示されて動かない……manコマンドも使えない、みたいな経験はありませんか?

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, including manpages, you can run the 'unminimize'
command. You will still need to ensure the 'man-db' package is installed.

これはDockerコンテナとしてアプリを実行する目的には不要である「インタラクティブな操作に関する機能」が削ぎ落とされている状態なのです。

Ubuntuの場合、Minimal Ubuntu(あるいはUbuntu Minimal Cloud Images)という、人が直接ログインして操作することを想定しない、クラウドやコンテナ向けに軽量化したものが使われているそうです。
(参考: 「Minimal Ubuntu」とは?Google Compute Engineで早速試してみた! | LFI

では普通のUbuntuのように使うことはできないのでしょうか?
いいえ、そんなことはありません。

unminimizeで通常のUbuntuに戻す

メッセージをよく読んでみると、文中にunminimizeというコマンドが出てきますね?

はい、UbuntuのDockerイメージの場合1は、unminimizeというコマンドを実行すると、削ぎ落とされていたコンテンツが復元されて、通常のUbuntu Serverとだいたい同じような状態になります。

root@486452421de5:/# unminimize
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

This script restores content and packages that are found on a default
Ubuntu server system in order to make this system more suitable for
interactive use.

Reinstallation of packages may fail due to changes to the system
configuration, the presence of third-party packages, or for other
reasons.

This operation may take some time.

Would you like to continue? [y/N]

実行するとこのようなメッセージが表示されるので、yを入力すると削ぎ落とされていたパッケージのインストールが始まります。
パッケージのインストール中にも yes/no を聞かれたりするので、yes | unminimizeというように実行するとよいでしょう。

追加のパッケージをインストールする

unminimizeしただけだと、manやその他のよく使うユーティリティは入っていないので、これらは別途インストールする必要があります。

apt install man-db vim git curl wget # などなど

Dockerなのでsystemdを使うといったことはできませんが、これでだいたい普通のUbuntuと同じように操作できるようになります。

  1. 他のディストリビューションの場合はどのような軽量化がされているのか、また、元に戻す方法は存在するのかなどは、調べていないのでわかりません。

10
2
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
10
2