サンプル集  >  other  >  Docker commit
Docker commit
2025/05/24

Docker commitコマンドでイメージを作成します。

◆環境
OS Windows 10 Home 22H2 64bit
Docker 27.4.0 build bde2b89

ubuntuのコンテナを起動しbashに接続します。

docker run -it ubuntu:20.04 bash
root@e92fd8a64646:/#

ubuntuを更新します。

root@e92fd8a64646:/# apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [128
 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
:

:
Fetched 35.6 MB in 44s (809 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
5 packages can be upgraded. Run 'apt list --upgradable' to see them.

rustをインストールします。

root@e92fd8a64646:/# curl --proto '=https' --tlsv1.2 -sSf https://sh.
rustup.rs | sh
bash: curl: command not found

curlコマンドがないというエラーがでたのでcurlをインストールします。

root@e92fd8a64646:/# apt install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  ca-certificates krb5-locales libasn1-8-heimdal libbrotli1 libcurl4 
libgssapi-krb5-2 libgssapi3-heimdal
:

:
  publicsuffix
0 upgraded, 32 newly installed, 0 to remove and 5 not upgraded.
Need to get 5468 kB of archives.
After this operation, 16.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Enterを押します。

Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libss
l1.1 amd64 1.1.1f-1ubuntu2.24 [1323 kB]
:

:
Processing triggers for ca-certificates (20240203~20.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

再度rustのインストールを試みます。

root@e92fd8a64646:/# curl --proto '=https' --tlsv1.2 -sSf https://sh.
rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /root/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargorustcrustup and other commands will be added to
Cargo's bin directory, located at:

  /root/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /root/.profile
  /root/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

1を入力しEnterを押します。

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
:

:
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.87.0 (17067e9ac
 2025-05-09)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leadin
g DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
source $"($nu.home-path)/.cargo/env.nu"  # For nushell

rustのバージョンを確認します。

root@e92fd8a64646:/# cargo --version
bash: cargo: command not found

rustをインストールしたときの最後にPATHにcargoを追加するようメッセージが出ていました。 そのコマンドを実行してみます。

root@e92fd8a64646:/# . "$HOME/.cargo/env"
root@e92fd8a64646:/# source "$HOME/.cargo/env.fish"
bash: /root/.cargo/env.fish: No such file or directory

/root/.cargo/env.fishというファイルが存在しないようです。 envを指定します。

root@e92fd8a64646:/# source "$HOME/.cargo/env"

もう一度rustのバージョンを確認します。

root@e92fd8a64646:/# cargo --version
cargo 1.87.0 (99624be96 2025-05-06)

コンテナを抜けます。

root@e92fd8a64646:/# exit

dockerの起動状態を確認します。

docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAME
S

-aを付けると停止しているコンテナも表示されます。

docker ps -a
CONTAINER ID   IMAGE          COMMAND   CREATED       STATUS         
             PORTS   NAMES
e92fd8a64646   ubuntu:20.04   "bash"    2 hours ago   Exited (0) 10 s
econds ago           silly_curran

rustをインストールしたコンテナからイメージを作ります。

イメージ名は「my-rust」とし、TAGに「commit」を記載します。

docker commit e92 my-rust:commit
sha256:7a44be3ea4030dbc8921052f99be162da7c3572e04fdb971858904ec5bbe33
63

イメージを確認するとmy-rustでTAGがcommitというイメージができていました。

docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
my-rust      commit    7a44be3ea403   3 minutes ago   1.91GB

bashで接続してみます。

docker run -it my-rust:commit bash
root@4ae411235b70:/# cargo --version
cargo 1.87.0 (99624be96 2025-05-06)
root@4ae411235b70:/# exit

イメージを作成することはできました。
ただ、docker commitだと環境構築の手順がわからなくなるようなのでおすすめしないようです。

▲ PageTop  ■ Home


Copyright (C) 2025 ymlib.com