实战一:docker制作自己的镜像
·
前言
由于docker市场的centos 镜像各种命令没有,所以自己制作centos镜像
环境准备
- 系统已经安装好docker
- 配置好docker镜像仓库
安装步骤
步骤1:制作镜像
1 拉取基础镜像
docker pull centos
2 进入容器
docker run -it centos
3 配置仓库yum阿里云镜像
下载 repo文件:https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
4 配置镜像源
#删除默认数据源
[root@61eb2710895c yum.repos.d]# rm -rf /etc/yum.repos.d/*
[root@61eb2710895c yum.repos.d]# vi CentOS-Base.repo
输入Centos-vault-8.5.2111.repo所有内容
[root@61eb2710895c yum.repos.d]# yum clean all && yum makecache
5 安装常用工具
[root@61eb2710895c yum.repos.d]# yum install -y telnet wget
#nslookup
[root@61eb2710895c yum.repos.d]# yum install -y bind-utils
#ifconfig
[root@61eb2710895c yum.repos.d]# yum install -y net-tools
#lsof
yum install -y lsof
#nginx 一定要装这个哦。要不部署k8s后无法启动容器
yum install -y nginx
/usr/sbin/nginx
6 退出容器
exit
步骤2:commit镜像
[root@localhost ~]# docker ps -a | grep centos
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc4974ce5b20 457400968e53 "/bin/bash" About a minute ago Exited...
#606aced135ff
[root@localhost ~]# docker commit dc4974ce5b20 mycentos:v1
#查看
[root@localhost ~]#docker images | grep mycentos
#至此 镜像制作完成
推送阿里云镜像私仓
[root@my-master ~]# docker tag nit-centos:v1 registry.cn-hangzhou.aliyuncs.com/nit/nit_centos:v1
[root@my-master ~]# docker push registry.cn-hangzhou.aliyuncs.com/nit/nit_centos:v1
k8s就可以从仓阿里云私仓库部署pod了
kind: Pod
apiVersion: v1
metadata:
name: nit-centos-0
generateName: nit-centos-
namespace: nit-middle-ware
labels:
app: nit-centos
controller-revision-hash: nit-centos-69595659d7
statefulset.kubernetes.io/pod-name: nit-centos-0
annotations:
cni.projectcalico.org/containerID: 82b871e5f34dedbc1a60bb7ef2717b05a3e9ff0ccd5b31b5174d9fc9b4b09363
cni.projectcalico.org/podIP: 10.233.67.2/32
cni.projectcalico.org/podIPs: 10.233.67.2/32
kubesphere.io/creator: admin
kubesphere.io/imagepullsecrets: '{"container-2v0ubi":"nit-harbor"}'
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
- name: kube-api-access-5dnwn
projected:
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
name: kube-root-ca.crt
items:
- key: ca.crt
path: ca.crt
- downwardAPI:
items:
- path: namespace
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
defaultMode: 420
containers:
- name: container-2v0ubi
image: 'registry.cn-hangzhou.aliyuncs.com/nit/nit_centos:v1'
#启动容器nginx挂起,要不会一直自动重启
command:
- /usr/sbin/nginx
args:
- '-g'
- daemon off;
ports:
- name: http-0
containerPort: 80
protocol: TCP
resources: {}
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
- name: kube-api-access-5dnwn
readOnly: true
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
nodeName: my-master
securityContext: {}
imagePullSecrets:
- name: nit-harbor
hostname: nit-centos-0
subdomain: nit-centos-55if
schedulerName: default-scheduler
tolerations:
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 300
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 300
priority: 0
enableServiceLinks: true
preemptionPolicy: PreemptLowerPriority
更多推荐
所有评论(0)