一.拉取轻量级基本镜像
docker pull index.tenxcloud.com/docker_library/alpine
二.配置Dockerfile
FROM index.tenxcloud.com/docker_library/rails
MAINTAINER author
#创建容器的工作路径
RUN mkdir -p /opt/rails
WORKDIR /opt/rails
RUN rails new blog
WORKDIR /opt/rails/blog
RUN bundle install
三. 生成镜像,推送到镜像仓库
docker build -f Dockerfile -t test-registry:5000/rails:v1.1 .
docker push test-registry:5000/rails:v1.1
四. 利用rc和svc 文件启动容器
rails-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rails
labels:
name: rails
labels:
name: rails
spec:
replicas: 1
selector:
name: rails
template:
metadata:
labels:
name: rails
spec:
containers:
- name: rails
image: test-registry:5000/rails:v1.1
imagePullPolicy: IfNotPresent
command: ["/opt/rails/blog/bin/rails","server","-b","0.0.0.0"]
rails-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: rails
labels:
name: rails
spec:
selector:
name: rails
type: NodePort
ports:
- port: 3000
targetPort: 3000
nodePort: 30000
kubectl create -f rails-rc.yaml,rails-svc.yaml