學習轉載:https://www.jianshu.com/p/c87b9ba51c67 linux
講dockerfile很好的文章:https://blog.csdn.net/wo18237095579/article/details/80540571git
新建gitserver鏡像的dockerfiledocker
FROM alpine:latestapi
MAINTAINER Ralph Wangapp
RUN apk add --no-cache openssh gitssh
RUN ssh-keygen -Aide
RUN adduser -D -s /bin/sh git && passwd -d git學習
RUN mkdir -p /opt/gitfetch
WORKDIR /optui
RUN chown -R git:git ./git
USER git
WORKDIR /home/git
RUN mkdir .ssh && chmod 700 .ssh && touch .ssh/authorized_keys && touch .ssh/known_hosts && chmod 600 .ssh/authorized_keys
EXPOSE 22
USER root
CMD /usr/sbin/sshd -D
生成鏡像
docker build -t gitserver:v1 .
編輯git-depoyment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitserver
labels:
app: gitserver
spec:
replicas: 1
selector:
matchLabels:
app: gitserver
template: # This is the pod template
metadata:
labels:
app: gitserver
spec:
containers:
- name: gitserver
image: gitserver:v1
imagePullPolicy: Never # Force to use 本地鏡像
ports:
- containerPort: 22
name: ssh
protocol: TCP
部署pods
kubectl create -f git-deployment.ymal
kubectl get pods
編輯git-ssh-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: gitserver
name: git-ssh # 服務的名稱
spec:
type: NodePort # 服務的 Type
ports:
- port: 22
targetPort: 22
name: ssh
selector:
app: gitserver
部署services
kubectl create -f git-ssh-service.yaml
kubectl get services
問題:
一、 [Warning] IPv4 forwarding is disabled. Networking will not work.
echo "net.ipv4.ip_forward = 1" /usr/lib/sysctl.d/00-system.conf
service network restart && systemctl restart docker
二、fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.g
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz: temporary error (try again later)
ERROR: unsatisfiable constraints:
git (missing):
required by: world[git]
openssh (missing):
required by: world[openssh]
The command '/bin/sh -c apk add --no-cache openssh git' returned a non-zero code : 2
問題1解決了,問題2也就消失了後來又卡在15/15最後一步
修改安裝源ok
RUN apk add --no-cache openssh git --repository=http://mirrors.aliyun.com/alpine/v3.8/community/
三、docker build -t gitserver:v1 .
Sending build context to Docker daemon 2.378GB(很大原來是把其它文件也傳過去了)
須要單獨建目錄存放dockerfile並在裏面運行就正常了