Kubernetes 简明教程
Kubernetes - Creating an App
要为 Kubernetes 部署创建应用程序,我们需要先在 Docker 上创建应用程序。这可以通过两种方式完成 -
In order to create an application for Kubernetes deployment, we need to first create the application on the Docker. This can be done in two ways −
-
By downloading
-
From Docker file
By Downloading
可以从 Docker 集线器下载现有映像,并可以存储在本地 Docker 注册表上。
The existing image can be downloaded from Docker hub and can be stored on the local Docker registry.
要做到这一点,请运行 Docker pull 命令。
In order to do that, run the Docker pull command.
$ docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from the registry
-a, --all-tags = false Download all tagged images in the repository
--help = false Print usage
以下是上述代码的输出。
Following will be the output of the above code.

上述屏幕截图显示了一组存储在我们的本地 Docker 注册表中的映像。
The above screenshot shows a set of images which are stored in our local Docker registry.
如果我们想要从包含要测试应用程序的映像构建容器,我们可以使用 Docker run 命令执行此操作。
If we want to build a container from the image which consists of an application to test, we can do it using the Docker run command.
$ docker run –i –t unbunt /bin/bash
From Docker File
要从 Docker 文件创建应用程序,我们需要先创建 Docker 文件。
In order to create an application from the Docker file, we need to first create a Docker file.
以下是 Jenkins Docker 文件的示例。
Following is an example of Jenkins Docker file.
FROM ubuntu:14.04
MAINTAINER vipinkumarmishra@virtusapolaris.com
ENV REFRESHED_AT 2017-01-15
RUN apt-get update -qq && apt-get install -qqy curl
RUN curl https://get.docker.io/gpg | apt-key add -
RUN echo deb http://get.docker.io/ubuntu docker main > /etc/apt/↩
sources.list.d/docker.list
RUN apt-get update -qq && apt-get install -qqy iptables ca-↩
certificates lxc openjdk-6-jdk git-core lxc-docker
ENV JENKINS_HOME /opt/jenkins/data
ENV JENKINS_MIRROR http://mirrors.jenkins-ci.org
RUN mkdir -p $JENKINS_HOME/plugins
RUN curl -sf -o /opt/jenkins/jenkins.war -L $JENKINS_MIRROR/war-↩
stable/latest/jenkins.war
RUN for plugin in chucknorris greenballs scm-api git-client git ↩
ws-cleanup ;\
do curl -sf -o $JENKINS_HOME/plugins/${plugin}.hpi \
-L $JENKINS_MIRROR/plugins/${plugin}/latest/${plugin}.hpi ↩
; done
ADD ./dockerjenkins.sh /usr/local/bin/dockerjenkins.sh
RUN chmod +x /usr/local/bin/dockerjenkins.sh
VOLUME /var/lib/docker
EXPOSE 8080
ENTRYPOINT [ "/usr/local/bin/dockerjenkins.sh" ]
创建上述文件后,请使用 Dockerfile 作为文件名保存它,并将 cd 作为文件路径。然后,运行以下命令。
Once the above file is created, save it with the name of Dockerfile and cd to the file path. Then, run the following command.

$ sudo docker build -t jamtur01/Jenkins .
构建映像后,我们可以测试映像是否运行正常,是否可以转换为容器。
Once the image is built, we can test if the image is working fine and can be converted to a container.
$ docker run –i –t jamtur01/Jenkins /bin/bash