Skip to content

Instantly share code, notes, and snippets.

@nezuppo
Last active August 31, 2022 12:06
Show Gist options
  • Save nezuppo/2458d512c72add0ad5609612cb0f0f26 to your computer and use it in GitHub Desktop.
Save nezuppo/2458d512c72add0ad5609612cb0f0f26 to your computer and use it in GitHub Desktop.

コマンドが一通り使える docker ubuntu イメージ作成


ホスト側で実施

docker hub から ubuntu 22.04 イメージを取得

$ docker pull ubuntu:22.04

イメージカスタマイズ用のコンテナ起動

$ docker run -it --name work-ubuntu2204 ubuntu:22.04

コンテナ内で実施

もろもろ ubuntu パッケージインストール

# apt update
# apt install -y \
  ubuntu-minimal \
  ubuntu-standard \
  ubuntu-server \
  net-tools

この後の apt -y full-upgrade で期待しないメッセージが出ないように不要なパッケージ needrestart を削除

# apt purge -y needrestart

念のため ubuntu パッケージを最新化

# apt update
# apt -y full-upgrade
# apt -y autoremove

作業用ユーザー作成

# useradd \
  --create-home \
  --groups sudo \
  --shell /bin/bash \
  worker

# echo 'worker:worker' | chpasswd
# su - worker -c 'mkdir /home/worker/Desktop'

コンテナ終了

# exit

ホスト側で実施

いろいろ作業を追加した上記の work-ubuntu2204 コンテナからイメージを作成

$ docker commit work-ubuntu2204 ubuntu:22.04-2

作業用のコンテナ work-ubuntu2204 はもう使わないので削除

$ docker rm work-ubuntu2204

ubuntu:22.04-2 イメージが出来たので、今後使わない予定の ubuntu:22.04 イメージは削除

$ docker image rm ubuntu:22.04

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment