開発用に雑な Ubuntu コンテナを作成する。
まずベースとなる Ubuntu 20.04 のイメージを取得してコンテナとして起動する。
取得するイメージでCMD ["/bin/bash"]
するようになっているのでそのまま bash が起動する。
% docker run --name="ubuntu2004" -it ubuntu:20.04 Unable to find image 'ubuntu:20.04' locally latest: Pulling from library/ubuntu 83ee3a23efb7: Pull complete db98fc6f11f0: Pull complete f611acd52c6c: Pull complete Digest: sha256:**************************************************************** Status: Downloaded newer image for ubuntu:20.04 root@b7057b8b4f14:/#
必要なものをインストールする。 ここではビルドに必要そうなパッケージを適当にインストールする。
root@d124e9c0dbdb:/# apt update root@d124e9c0dbdb:/# apt install -y curl vim git net-tools build-essential
終わったらbash
を終了させて、コンテナを停止する。
root@d124e9c0dbdb:/# exit
docker commit
でイメージを保存して、タグをつける。
% docker commit ubuntu2004 localhost/ubuntu2004:v1.0.0 sha256:****************************************************************
イメージを確認する。
% docker images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/ubuntu2004 v1.0.0 2cf5d123178e 23 seconds ago 448MB ubuntu 20.04 f63181f19b2f 5 weeks ago 72.9MB
作成したイメージからコンテナを起動する。
% docker run -it localhost/ubuntu2004:v1.0.0 root@d124e9c0dbdb:/#
補足
ある程度固まったらDockerfile
にして再利用性を高める。
FROM ubuntu:20.04 RUN apt update && \ apt -y install curl vim git net-tools build-essential
% docker build -t localhost/ubuntu2004:v1.0.0 .
% docker run -it localhost/ubuntu2004:v1.0.0