黑猴子的家:Dockerfile镜像管理

Dockerfile镜像管理

1、创建目录结构
[root@node1 ~]# mkdir docker
[root@node1 ~]# cd docker
[root@node1 docker]# mkdir -p system/centos/
…….
[root@node1 docker]# tree
尖叫提示:Dockerfile要写在gitHub上,防止丢失、方便修改
黑猴子的家:Dockerfile镜像管理_第1张图片
image.png
2、下载EPEL源
[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3、系统层

centos:base

[root@node1 ~]# cd /opt/docker/system/centos
[root@node1 centos]# cp /etc/yum.repos.d/epel.repo .
[root@node1 centos]# touch Dockerfile
[root@node1 centos]# vim Dockerfile
#Docker for CentOS
#Base images
FROM centos
#who
MAINTAINER Victor.Liu [email protected]
#EPEL
ADD epel.repo /etc/yum.repo.d/
#Base pkg
RUN yum install -y wget mysql-devel git redis tree net-tools sudo psmisc vim epel-release python-setuptools
RUN wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
RUN yum install -y supervisor python-pip
RUN yum clean all
[root@node1 centos]# docker build -t victor/centos:base ./

centos-ssh: latest

[root@node1 ~]# cd /opt/docker/system/centos-ssh
[root@node1 centos-ssh]# cp /etc/yum.repos.d/epel.repo ./
[root@node1 centos-ssh]# touch Dockerfile
[root@node1 centos-ssh]# vim Dockerfile
#Docker for CentOS
#Base images
FROM victor/centos:base
#who
MAINTAINER Victor.Liu [email protected]
#EPEL
ADD epel.repo /etc/yum.repo.d/
#Base pkg
RUN yum install -y openssh-clients openssl-devel openssh-server wget mysql-devel supervisor git redis tree net-tools sudo psmisc vim && yum clean all
#For SSHD
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
RUN echo "root:oldboy" | chpasswd
[root@node1 centos-ssh]# docker build -t victor/centos-ssh ./
4、运行环境层

python

[root@node1 ~]# cd /opt/docker/runtime/python
[root@node1 python]# vim Dockerfile
FROM victor/centos:base
#who
MAINTAINER Victor.Liu [email protected]
RUN yum -y install python-devel python-pip supervisor && yum clean all
RUN pip install --upgrade pip
[root@node1 python]# docker build -t victor/python ./

python-ssh

[root@node1 ~]# cd /opt/docker/runtime/python-ssh
[root@node1 python-ssh]# vim Dockerfile
FROM victor/centos-ssh
#who
MAINTAINER Victor.Liu [email protected]
RUN yum -y install python-devel python-pip supervisor && yum clean all
RUN pip install --upgrade pip
[root@node1 python-ssh]# docker build -t victor/python-ssh ./
5、服务层

app.py 简单测试代码

[root@node1 ~]# cd /opt/docker/app/shop-app
[root@node1 shop-app]# vim app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
 return 'Hello World!'
if __name__ == "__main__":
 app.run(host="0.0.0.0", debug=True)

app-supervisor.ini

[root@node1 ~]# cd /opt/docker/app/shop-app
[root@node1 shop-app]# vim app-supervisor.ini
[program:shop-api]
Command=/usr/bin/python2.7 /opt/app.py
Process_name=%(program_name)s
autostart=true
user=root
stdout_logfile=/tmp/app.log
stderr_logfile=/tmp/app.error
[program:sshd]
Command=/usr/sbin/sshd -D
Process_name=%(program_name)s
autostart=true

requirements.txt

[root@node1 ~]# cd /opt/docker/app/shop-app
[root@node1 shop-app]# vim requirements.txt
flask

supervisord.conf

[root@node1 ~]# cd /opt/docker/app/shop-app
[root@node1 shop-app]# cp /etc/supervisord.conf ./
[root@node1 shop-app]# vim supervisord.conf
nodaemon=true

Dockerfile

[root@node1 ~]# cd /opt/docker/app/shop-app
[root@node1 shop-app]# vim Dockerfile
FROM victor/python-ssh
#who
MAINTAINER Victor.Liu [email protected]
RUN useradd -s /sbin/nologin -M www
ADD app.py /opt/app.py
ADD requirements.txt /opt/
ADD supervisord.conf /etc/supervisord.conf
ADD app-supervisor.ini /etc/supervisord.d/
#whereis pip
RUN /usr/bin/pip2.7 install -r /opt/requirements.txt
#Port
EXPOSE 22 5000
#CMD whereis supervisord
CMD ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
[root@node1 shop-app]# docker build victor/shop-api ./

基于镜像启动容器,浏览器访问node1:88,xshell访问node1的8022端口

[root@node1 shop-app]# docker run --name shop-api -d -p 88:5000 -p 8022:22 victor/shop-api

你可能感兴趣的:(黑猴子的家:Dockerfile镜像管理)