Dockerfile 文件如下:

#
# MAINTAINER Carson,C.J.Zeong <zcy@nicescale.com>
# DOCKER-VERSION 1.6.
#
# Dockerizing CentOS7: Dockerfile for building CentOS images
#
#基础镜像来自:centos7
FROM centos:centos7.1.1503
#维护者信息
MAINTAINER XXXXX <XXX@XXX.com> #evn 是环境的意思
ENV TZ "Asia/Shanghai"
ENV TERM xterm # Add和copy都是复制文件的命令,但是add比copy 好:add可支持连接地址同时对于压缩文件可以自动解压
ADD aliyun-mirror.repo /etc/yum.repos.d/CentOS-Base.repo
ADD aliyun-epel.repo /etc/yum.repos.d/epel.repo #安装了基础的工具和软件
RUN yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
yum install -y gcc gcc-c++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel && \
yum install -y --enablerepo=epel pwgen python-pip && \
yum clean all #使用pip安装进程管理工具
RUN pip install supervisor
#复制本地文件到镜像机器的相应目录
ADD supervisord.conf /etc/supervisord.conf #创建需要用到的其他目录,这里是启动其他文件的配置文件和日志文件
RUN mkdir -p /etc/supervisor.conf.d && \
mkdir -p /var/log/supervisor #暴露22端口
EXPOSE #只有最后ENTRYPOINT一条生效
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

同时在和Dockerfile 文件的同级目录下有如下文件:

aliyun-mirror.repo文件

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 
aliyun-epel.repo文件
[epel]
name=Extra Packages for Enterprise Linux - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=
gpgcheck=
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo]
name=Extra Packages for Enterprise Linux - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck= [epel-source]
name=Extra Packages for Enterprise Linux - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=
supervisord.conf文件
 
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod= ; socket file mode (default ) [supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB
logfile_backup=
loglevel=info
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (Start in foreground if true; default false)
minfds= ; (min. avail startup file descriptors;default )
minprocs= ; (min. avail process descriptors;default ) [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket [include]
files = /etc/supervisor.conf.d/*.conf

开始build镜像:

命令的最后的点表示当前目录,正如你所看的(ls 命令查看),当前目录下有Dockerfile 文件 这里只用点(.) 就可以了,不然要用正确的路径。

上图也就是docker的第一层(step1)操作。

后面的操作类似都会根据Dockerfile配置的执行。

然后查看docker镜像,这里已经有了。

然后运行容器,docker run:

-d 表示后台运行(把容器的长id返回),-p 表示端口映射, --name 表示该容器的别名,,最后返回容器的id号。(-P(大写)的话宿主机会随机给一个端口与改容器需要使用的端口(这里是22)做映射。)

查看容器(加 -a 表示查看全部):

基础镜像已经完成。

												

Centos7 docker容器 搭建的更多相关文章

  1. Docker容器搭建android编译环境

    Docker容器搭建android编译环境 目录 1 部署容器 1.1 手动部署 1.1.1 配置docker 1.1.2 启动容器 1.1.3 配置环境 1.2 Dockerfile 2 镜像管理 ...

  2. CentOS7 Docker容器无法ping通宿主机ip问题解决记录

    Docker服务部署启动容器发现docker容器内访问宿主机IP不通,于是进入容器内ping宿主机IP,发现无法ping通,容器IP为172.17.0.2,于是继续ping172.17.0.1也不通, ...

  3. Centos7 docker容器启动后添加端口映射

    docker容器启动后添加端口映射的两种方法: 一.通过修改防火墙策略添加端口映射 docker容器已创建好,但是想在容器内配置tomcat监控,需要新的端口去访问,但是映射时没有映射多余端口,此时, ...

  4. 解决CentOS7 docker容器映射端口只监听ipv6的问题

    问题现象 docker容器起来以后,查看9100端口监听情况,如下图: $ ss -lntp State Recv-Q Send-Q Local Address:Port Peer Address:P ...

  5. php-fpm docker 容器 搭建

    继续上一篇文章(centos 7 容器的搭建) 下面构建一个php-fpm镜像: dockerfile 文件如下: # # MAINTAINER # DOCKER-VERSION # # Docker ...

  6. 基于docker容器搭建fastdfs分布式文件系统

    本次环境的搭建参考了 https://blog.csdn.net/qq_43455410/article/details/84797814, 感谢博主. 主要流程如下: 1. 下载fastdfs镜像 ...

  7. 基于 docker容器搭建机器学习环境

    下载docker镜像 docker pull ubuntu:18.04 进入ubuntu系统命令 docker run -ti ubuntu /bin/bash 正确退出系统方式 先按,ctrl+p ...

  8. 利用远程服务器在docker容器搭建pyspider运行时出错的问题

    This system supports the C.UTF-8 locale which is recommended. You might be able to resolve your issu ...

  9. 浅析Docker容器的应用场景

    本文来自网易云社区 作者:娄超 过去几年开源界以openstack为代表的云计算持续火了好久,这两年突然又冒出一个叫Docker的容器技术,其发展之迅猛远超预料.网上介绍Docker容器的文章已经很多 ...

随机推荐

  1. IO-Polling的代码分析

    在前一篇文章<IO-Polling实现分析与性能评測>中提到了IO-Polling与中断的原理差别,并通过两种模式下NVMe SSD的性能測试对两者进行了对照. 这篇文章将深入到IO-Po ...

  2. Unity3d Resources TextAsset 文本

    一些小型数据,可以用txt文本作为媒介,进行获取.传输.修改.存储: 比如:User1.2.3.txt,放入 Resources/Data 文件下: 一,Unity3d Resources.Load ...

  3. 带参数的main函数

    带参数的main函数 int main(int argc,char **argv)  或int main(int argc,char *argv[])  /*解析 依据<C程序设计语言(第二版. ...

  4. 如何理解docker镜像build中的上下文

    参考:https://yeasy.gitbooks.io/docker_practice/content/image/build.html 理解上线文概念非常重要,不然可能碰到一些奇怪的问题. 构建镜 ...

  5. django的ORM中的2个易混点

    1.django数据模型中null=True和blank=True的区别 null 是针对数据库而言,如果 null=True, 表示数据库的该字段可以为空,即在Null字段显示为YES. blank ...

  6. 巨蟒django之CRM1 需求分析&&表结构设计&&注册登录验证

    1.需求分析 .项目 ()业务 ()权限的管理 .CRM customer relationship management 客户关系管理系统 .谁来使用CRM? 销售&&班主任& ...

  7. C# 调用ArcGIS server admin api

    一.AGS server admin api 介绍 1.1什么是admin api AGS Server Admin api 官方的称呼是 AGS Server administrator api, ...

  8. http-proxy-middleware使用方法和实现原理(源码解读)

    本文主要讲http-proxy-middleware用法和实现原理. 一 简介 http-proxy-middleware用于后台将请求转发给其它服务器. 例如:我们当前主机A为http://loca ...

  9. 插叙LTE

  10. Codeforces 240F. TorCoder 线段树

    线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...