一、简介
- 本文主要介绍如何使用docker安装centos镜像。
- 有了centos镜像之后,就可以在该镜像中安装一些环境,软件等等,方便复制。
- 一般有俩种方式安装,一种是直接拉取开源的镜像,一种是使用dockerfile定制安装。
二、拉取开源镜像安装
2.1 查询开源centos镜像
- 使用docker search 命令来查询开源镜像;
[root@yuanshushu ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 5649 [OK]
ansible/centos7-ansible Ansible on Centos7 125 [OK]
jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos - … 114 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 100 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 64
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 … 39
kinogmt/centos-ssh CentOS with SSH 29 [OK]
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 10
guyton/centos6 From official centos6 container with full up… 9 [OK]
drecom/centos-ruby centos ruby 6 [OK]
centos/tools Docker image that has systems administration… 4 [OK]
darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
mamohr/centos-java Oracle Java 8 Docker image based on Centos 7 3 [OK]
pivotaldata/centos Base centos, freshened up a little with a Do… 3
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 2
miko2u/centos6 CentOS6 日本語環境 2 [OK]
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 2
indigo/centos-maven Vanilla CentOS 7 with Oracle Java Developmen… 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
mcnaughton/centos-base centos base image 1 [OK]
pivotaldata/centos7-dev CentosOS 7 image for GPDB development 0
smartentry/centos centos with smartentry 0 [OK]
pivotaldata/centos6.8-dev CentosOS 6.8 image for GPDB development 0
2.2 下载官方开源镜像
- 下载的默认是最新的,我也不知道是不是centos7版本。。。。
[root@yuanshushu ~]# docker pull centos
- 查看本地镜像
[root@yuanshushu ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0f3e07c0138f 5 weeks ago 220MB
2.3 创建容器并运行
- 基于镜像centos:latest镜像创建一个名称为centos-01的容器,并进入;
- -t: 在新容器内指定一个伪终端或终端;
- -i: 允许你对容器内的标准输入 (STDIN) 进行交互;
- –name: 为命名容器名称;
- centos为源镜像名称;
- /bin/bash 为 进入新的容器centos-01;
- 注意:进入之后,@后面的名称就改为了容器id;
[root@yuanshushu ~]# docker run -it --name centos-01 centos /bin/bash
[root@8e2b1edba516 /]#
- 也可以使用-d命令来后台启动容器,然后使用attach进入
[root@yuanshushu ~]# docker run -itd --name centos-002 centos /bin/bash
aeb0617e6a98d9282ae4cb00ef2de38e0f172f832db5d3ac72fa7cfe680aef92
[root@yuanshushu ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aeb0617e6a98 centos "/bin/bash" 14 seconds ago Up 13 seconds centos-002
[root@yuanshushu ~]# docker attach aeb0617e6a98
[root@aeb0617e6a98 /]#
- 此时可以查看centos-01内部文件结构,如下:
[root@8e2b1edba516 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
- 可以使用exit命令退出容器
- 注意此时@已经回退到宿主机上了
[root@737b37aa53df /]# exit
exit
[root@yuanshushu ~]#
- 查看所有的容器
[root@yuanshushu ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab7dc6a5f4ae centos:latest "/bin/bash" 8 minutes ago Exited (0) 8 minutes ago centos-001
8e2b1edba516 centos "/bin/bash" 13 minutes ago Exited (127) 10 minutes ago centos-01
三、使用dockerfile安装
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/17701.html