在docker下创建自己的image

    xiaoxiao2022-06-23  19

    简介:介绍两种方式创建image:从Dockerfile 生成新的image,使用docker build命令;在原有image上改进生成新的image,直接pull  image,install  and commit; 

    方式一:在原有image上通过Dockerfile生成新的image

    eg:在ubuntu 14.04 版本上添加ruby 功能

    第一步. 编辑Dockerfile

      root@ubuntu-daisy:~# mkdir daisy_dockerbuild

    root@ubuntu-daisy:~# ls

    bamboo  daisy_dockerbuild  index.html  sinatra

    root@ubuntu-daisy:~# cd daisy_dockerbuild/

    root@ubuntu-daisy:~/daisy_dockerbuild# touch Dockerfile

    root@ubuntu-daisy:~/daisy_dockerbuild# ls Dockerfile

    打开Dockfile 编辑内容:

    root@ubuntu-daisy:~/daisy_dockerbuild# vim Dockerfile

    root@ubuntu-daisy:~/daisy_dockerbuild# cat Dockerfile FROM ubuntu:14.04 RUN export http_proxy=http://proxy-prc.webl.com:911 && export https_proxy=https://proxy-prc.web.com:911 && apt-get update && apt-get install -y ruby ruby-dev 开始build  image root@ubuntu-daisy:~/daisy_dockerbuild# docker build -t ubuntu . Sending build context to Docker daemon 2.048 kB Step 1 : FROM ubuntu:14.04   ---> 4a725d3b3b1c Step 2 : RUN export http_proxy=http://proxy-prc.intel.com:911 && export https_proxy=https://proxy-prc.intel.com:911 && apt-get update && apt-get install -y ruby ruby- dev  ---> Using cache   ---> 6b2695fa32bf Successfully built 6b2695fa32bf

    查看已经建立成功

    root@ubuntu-daisy:~/daisy_dockerbuild# docker images REPOSITORY                  TAG                 IMAGE ID            CREATED                    SIZE ubuntu                      latest              6b2695fa32bf        About an hour ago           306.8 MB

    方式二:在原有image上改进生成新的image

      首先查找你需要的image

    root@ubuntu-daisy:~# docker search sinatra NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED hwada/sinatra                               sinatra for hands on of aws-docker-fluentd-s3   0                    [OK] kerona/sinatra                                                                               0                    [OK] root@ubuntu-daisy:~# docker pull kerona/sinatra

    以kerona/sinatra 容器为基础,再建一个container root@ubuntu-daisy:~# docker run -t -i kerona/sinatra /bin/bash

    root@7199eb77c75c:/# export http_proxy=http://proxy-prc.web.com:911        // 设置代理 root@7199eb77c75c:/# export https_proxy=https://proxy-prc.web.com:911

    root@7199eb77c75c:/# apt-get install -y ruby2.0-dev Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed:   ruby2.0-dev 0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded. Need to get 908 kB of archives. After this operation, 4323 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main ruby2.0-dev amd64 2.0.0.484-1ubuntu2.2 [908 kB] Fetched 908 kB in 2s (306 kB/s) Selecting previously unselected package ruby2.0-dev:amd64. (Reading database ... 16609 files and directories currently installed.) Preparing to unpack .../ruby2.0-dev_2.0.0.484-1ubuntu2.2_amd64.deb ... Unpacking ruby2.0-dev:amd64 (2.0.0.484-1ubuntu2.2) ... Setting up ruby2.0-dev:amd64 (2.0.0.484-1ubuntu2.2) ...

    root@ubuntu-daisy:~# docker commit -m "Added ruby" -a "daisy" 62b83f189561 daisy/sinatra:v2 sha256:203b756a3edfd0f617a8e41dfefe3f411c41b4e3388b07cf012fdbe4a8b3ebb2

    查看已经生成了自己的image root@ubuntu-daisy:~# docker images REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE daisy/sinatra               v2                  203b756a3edf        16 seconds ago      316.4 MB

    两种方法,其中方法一更方便使用,也便于team内共享。在创建own image 时,我需要每次都设置http是因为公司网络是代理的缘故,正常情况不用设置就能连上网。

    转载请注明原文地址: https://ju.6miu.com/read-1123292.html

    最新回复(0)