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能看到界面