针对后端容器镜像管理,可以采用以下步骤:
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]
其中,FROM指定了基础镜像,RUN指定了安装nginx的指令,CMD指定了容器启动后执行的命令。
docker build -t my-nginx .
其中,-t指定了镜像的名称和标签,.表示Dockerfile所在的目录。
docker push my-nginx
其中,my-nginx为镜像名称和标签。
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
selector:
matchLabels:
app: my-nginx
replicas: 3
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: my-nginx
image: my-nginx
ports:
- containerPort: 80
其中,image指定了使用的镜像名称和标签。
关键词高亮:Dockerfile、构建镜像、Docker Hub、私有仓库、后端应用、Deployment、replicas、containers、image。