s2i 制作httpd镜像(最简单的例子)-hjimmy

1.下载s2i工具

https://github.com/openshift/source-to-image/releases/

 

下载对应版本的介质后,解压缩后得到二进制文件: s2i  sti 

 将s2i和sti拷贝到目录:/usr/bin/下

2.  下载社区centos镜像

#docker pull docker.io/centos:latest

 3.   制作s2i镜像,并修改文件

# mkdir /home/test
# cd /home/test
# s2i create docker.io/centos:latest s2i-httpd-centos
# ls s2i-httpd-centos
Dockerfile  Makefile  README.md  s2i  test
test目录下有 test/test-app/index.html ,该文件可理解为源码文件。

1) 修改Dockerfile

# centos
FROM docker.io/centos:latest
MAINTAINER jian.hou <jian.hou@cs2c.com.cn>

# Inform about software versions being used inside the builder
ENV HTTPD_VERSION=X.XX.XX

# Set labels used in OpenShift to describe the builder images
LABEL io.k8s.description="Platform for serving static HTML files" \
      io.k8s.display-name="httpd x.xx.xx" \
      io.openshift.expose-services="80:http" \
      io.openshift.tags="builder,html,httpd"

# Install the required software, namely httpd and
RUN yum install -y httpd
LABEL io.openshift.s2i.scripts-url=image:///usr/local/s2i

# Copy the S2I scripts from ./.s2i/bin/ to /usr/local/s2i when making the builder image
COPY ./s2i/bin/ /usr/local/s2i

# Copy the httpd configuration file
# COPY ./etc/ /opt/app-root/etc

# Drop the root user and make the content of /opt/app-root owned by user 1001
RUN chown -R apache:apache /var/www/html/

# Set the default user for the image, the user itself was created in the base image
USER root

# Specify the ports the final image will expose
EXPOSE 80

# Set the default CMD to print the usage of the image, if somebody does docker run
CMD ["usage"]

2)  修改s2i/bin/run

#!/bin/bash -e
#
# S2I run script for the 'centos' image.
# The run script executes the server that runs your application.
#
# For more information see the documentation:
#       https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#

exec /usr/sbin/httpd -D FOREGROUND

3)  修改s2i/bin/assemble

#!/bin/bash -e
#
# S2I assemble script for the 'centos' image.
# The 'assemble' script builds your application source so that it is ready to run.
#
# For more information refer to the documentation:
#       https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#

echo "---> Installing application source..."
# 该过程将目标代码,拷贝到指定目录
cp -Rf /tmp/src/. /var/www/html
# 赋予新拷贝文件的权限
chown -R apache:apache /var/www/html/

4) 制作普通镜像

# 该操作可以制作镜像
# cd s2i-httpd-centos
在dockfile中将From 修改成麒麟系统
# make 

5) 创建s2i镜像

# 将步骤4) 制作的镜像,结合test-app制作成运行的镜像
#s2i build test/test-app/ docker.io/centos:latest sample-app
#docker images
会看到镜像sample-app
# docker run -p 8082:80 sample-app
  访问本其的本机IP:8082能看到界面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值