您的位置:首页 > 运维架构 > Docker

Docker 容器镜像制作(python程序)

qq_28513801 2019-06-24 14:53 549 查看

话不多说,本篇是为上面一篇Compose服务的
首先拉取centos镜像

[root@devops ~]# docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   5421                [OK]
ansible/centos7-ansible            Ansible on Centos7                              121                                     [OK]
jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.6.1810 x86…   110                                     [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   91                                      [OK]
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              57                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      44
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   37
kinogmt/centos-ssh                 CentOS with SSH                                 27                                      [OK]
centos/php-56-centos7              Platform for building and running PHP 5.6 ap…   20
guyton/centos6                     From official centos6 container with full up…   10                                      [OK]
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   10
drecom/centos-ruby                 centos ruby                                     6                                       [OK]
pivotaldata/centos                 Base centos, freshened up a little with a Do…   3
darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
miko2u/centos6                     CentOS6 日本語環境                                   2                                       [OK]
pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   2
ovirtguestagent/centos7-atomic     The oVirt Guest Agent for Centos 7 Atomic Ho…   2
pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   1
mcnaughton/centos-base             centos base image                               1                                       [OK]
blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developmen…   1                                       [OK]
smartentry/centos                  centos with smartentry                          0                                       [OK]
pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0
pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0
fortinj66/centos7-s2i-nodejs       based off of ryanj/centos7-s2i-nodejs.  Bigg…   0
[root@devops ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:b5e66c4651870a1ad435cd75922fe2cb943c9e973a9673822d1414824a1d0475
Status: Downloaded newer image for centos:latest
[root@devops ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
portainer/portainer   latest              da2759008147        2 weeks ago         75.4MB
centos                latest              9f38484d220f        3 months ago        202MB
[root@devops ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
fc7181108d40: Pull complete
c4277fc40ec2: Pull complete
780053e98559: Pull complete
Digest: sha256:bdbf36b7f1f77ffe7bd2a32e59235dff6ecf131e3b6b5b96061c652f30685f3a
Status: Downloaded newer image for nginx:latest

这里我们登陆一下的私有仓库

[root@devops ~]# docker login --username=抛物线linux registry.cn-beijing.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

然后开启运行一个镜像

[root@devops ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
nginx                 latest              719cd2e3ed04        12 days ago         109MB
portainer/portainer   latest              da2759008147        2 weeks ago         75.4MB
centos                latest              9f38484d220f        3 months ago        202MB
[root@devops ~]# docker run -itd --name centospython --net=bridge centos /bin/bash
16f0c37e1fdd4ba18ff346b3a8444da1ff64cbff236417bf736760c9fccc182f
[root@devops ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
16f0c37e1fdd        centos              "/bin/bash"         3 seconds ago       Up 2 seconds                            centospython
[root@devops ~]# docker exec -it 16f0c37e1fdd  /bin/bash
[root@16f0c37e1fdd /]# ip a

[root@16f0c37e1fdd /]# yum search ifconfig
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
base                                                                                                            | 3.6 kB  00:00:00
extras                                                                                                          | 3.4 kB  00:00:00
updates                                                                                                         | 3.4 kB  00:00:00
(1/4): base/7/x86_64/group_gz                                                                                   | 166 kB  00:00:01
(2/4): extras/7/x86_64/primary_db                                                                               | 205 kB  00:00:01
(3/4): base/7/x86_64/primary_db                                                                                 | 6.0 MB  00:00:01
(4/4): updates/7/x86_64/primary_db                                                                              | 6.4 MB  00:00:24
========================================================== Matched: ifconfig ==========================================================
net-tools.x86_64 : Basic networking tools
[root@16f0c37e1fdd /]# yum install -y net-tools.x86_64
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.24.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
Package                       Arch                       Version                                       Repository                Size
=======================================================================================================================================
Installing:
net-tools                     x86_64                     2.0-0.24.20131004git.el7                      base                     306 k

Transaction Summary
=======================================================================================================================================
Install  1 Package

Total download size: 306 k
Installed size: 918 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.24.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for net-tools-2.0-0.24.20131004git.el7.x86_64.rpm is not installed
net-tools-2.0-0.24.20131004git.el7.x86_64.rpm                                                                   | 306 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                           1/1
Verifying  : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                           1/1

Installed:
net-tools.x86_64 0:2.0-0.24.20131004git.el7

Complete!
[root@16f0c37e1fdd /]#
[root@16f0c37e1fdd /]#

[root@16f0c37e1fdd /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
RX packets 4292  bytes 13959608 (13.3 MiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 3860  bytes 211812 (206.8 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
inet 127.0.0.1  netmask 255.0.0.0
loop  txqueuelen 0  (Local Loopback)
RX packets 0  bytes 0 (0.0 B)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 0  bytes 0 (0.0 B)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@16f0c37e1fdd /]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

然后把我们的该容器打包成镜像

[root@devops ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
16f0c37e1fdd        centos              "/bin/bash"         21 minutes ago      Up 21 minutes                           centospython
[root@devops ~]# docker export 16f0c37e1fdd     > python3tar
[root@devops ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  python3tar
[root@devops ~]# mv python3tar /opt/
[root@devops ~]# cat /opt/python3tar | docker import - python3:test
sha256:6121878c45f969eaef26aef5b193029ae396c53714ead35d19e67b122975cf31
[root@devops ~]# docker images | grep python3
python3               test                6121878c45f9        9 seconds ago       284MB
[root@devops ~]#

这里由于compose中使用的是python2.7 的镜像 那么我们就重新tag 一下

[root@devops ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
python3               test                6121878c45f9        53 seconds ago      284MB
python                2.7                 693b5f09c0ee        7 minutes ago       307MB
nginx                 latest              719cd2e3ed04        12 days ago         109MB
portainer/portainer   latest              da2759008147        2 weeks ago         75.4MB
centos                latest              9f38484d220f        3 months ago        202MB
[root@devops ~]# docker tag python3:test python2.7:test
[root@devops ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED              SIZE
python2.7             test                6121878c45f9        About a minute ago   284MB
python3               test                6121878c45f9        About a minute ago   284MB
python                2.7                 693b5f09c0ee        8 minutes ago        307MB
nginx                 latest              719cd2e3ed04        12 days ago          109MB
portainer/portainer   latest              da2759008147        2 weeks ago          75.4MB
centos                latest              9f38484d220f        3 months ago         202MB
[root@devops ~]#

好了 制作已经结束,继续上篇我们的compose

标签: 
章节导航