LoginSignup
0
0

More than 1 year has passed since last update.

Docker Imageの作成(Windows)

Posted at

Docker Imageの作成(Windows)

Docker Hubを使用しない方法(ローカルPCで作成方法)

  • docker commitコマンドを使用します。

  • Pythonでnumpyモジュールを使用したく環境を構築する例で説明します。

Python&numpyモジュールDockerのImageを構築する

  1. PythonをDockerにインストールします。

    1. Python Office ImageでインストールしたいバージョンのPythonを検索してコマンドをコピーします。

    2. コマンドプロンプトにて実行させます。下記のようなログが出ましたら完了とします。

        >docker pull python:3.11.1
        3.11.1: Pulling from library/python
        bbeef03cda1f: Pull complete
        f049f75f014e: Pull complete
        56261d0e6b05: Pull complete
        9bd150679dbd: Pull complete
        5b282ee9da04: Pull complete
        03f027d5e312: Pull complete
        741e8aa30cc2: Pull complete
        5ceb79cda400: Pull complete
        f2c00c886d59: Pull complete
        Digest: sha256:5f004bbd8b9b6ae1478fee7d4dfbf38305af7188946aa79925667fa658458ba9
        Status: Downloaded newer image for python:3.11.1
        docker.io/library/python:3.11.1
      
  2. pipを使用してnumpyをインストールします。

    1. まずpythonのコンテナを立ち上げます。

      docker run -i -t python:3.11.1 /bin/bash

    2. numpyをインストールします。

      • pip listでnumpyが入っていないことを確認します。

      • numpyをインストールします。

          root@bf3ae658fb55:/# pip install numpy
          Collecting numpy
           Downloading numpy-1.24.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 5.6 MB/s eta 0:00:00
          Installing collected packages: numpy
          Successfully installed numpy-1.24.1
        
      • pip listでnumpyが入っていることを確認できます。

    3. 一旦終了します。

      • root@bf3ae658fb55:/# exit
  3. Docker Imageを作成します。

    1. Dockerコンテナを確認します。

      >docker ps -a
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
      bf3ae658fb55 python:3.11.1 "/bin/bash" 5 minutes ago Exited (0) 2 minutes ago jolly_ramanujan
      
    2. コンテナのNAMESdocker commitを利用してDocker Imageを作成します。

      docker commit jolly_ramanujan numpy_image_test
      sha256:c6ab95539a0e5daa10650e59dcd8a5f129820a7ab93a41d495433cb47d566ae3
      

これでDocker Imageの作成ができましたので、確認しましょう。

作成したnumpy_image_testの確認

  1. docker imagesを使ってnumpy_image_testがあることを確認します。

    REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
    numpy_image_test   latest    c6ab95539a0e   4 minutes ago    1.03GB
    
  2. numpy_image_testのコンテナを一つ作ります。

    docker run -i -t numpy_image_test /bin/bash
    
  3. numpyがあるかどうかを確認します。

    root@467e7e642188:/# pip list
    Package    Version
    ---------- -------
    numpy      1.24.1
    pip        22.3.1
    setuptools 65.5.1
    wheel      0.38.4
    

numpyが入っているので、Docker Imageの作成が成功ですね!!!

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