yaml如何与docker-compose.yml配合使用?

来源:10-4 k8s调度的最小单位pod(下)

DominiY

2021-07-07

老师,请教一下,yaml如何与docker-compose.yml配合使用?

我在本地使用docker-compose up --build -d能正常使用,但是编写了yaml后报错

Failed to pull image “potato.api.service”: rpc error: code = Unknown desc = Error response from daemon: pull access denied for potato.api.service, repository does not exist or may require ‘docker login’

docker-compose.env

NAMESPACE=
LOGGER=true
LOGLEVEL=info
SERVICEDIR=services

TRANSPORTER=TCP

docker-compose.yml

version: "3.3"

services:
  api:
    build:
      context: .
    image: potato.api.service
    env_file: docker-compose.env
    environment:
      SERVICES: api
      PORT: 8888
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
      - "traefik.http.services.api-gw.loadbalancer.server.port=8888"
    networks:
      - internal

  user:
    build:
      context: .
    image: potato.user.service
    env_file: docker-compose.env
    environment:
      SERVICES: user
    networks:
      - internal

  traefik:
    image: traefik:v2.1
    command:
      - "--api.insecure=true" # Don't do that in production!
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
    ports:
      - 8888:80
      - 4001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - internal
      - default

networks:
  internal:

volumes:
  data:

k8s.yaml

#########################################################
# Common Environment variables ConfigMap
#########################################################
apiVersion: v1
kind: ConfigMap
metadata:
  name: common-env
data:
  NAMESPACE: ""
  LOGLEVEL: info
  SERVICEDIR: services

---
#########################################################
# Service for Moleculer API Gateway service
#########################################################
apiVersion: v1
kind: Service
metadata:
  name: api
spec:
  selector:
    app: api
  ports:
    - port: 8888
      targetPort: 8888

---
#########################################################
# API Gateway service
#########################################################
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  selector:
    matchLabels:
      app: api
  replicas: 2
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: potato.api.service
          envFrom:
            - configMapRef:
                name: common-env
          env:
            - name: SERVICES
              value: api

---
#########################################################
# user service
#########################################################
apiVersion: apps/v1
kind: Deployment
metadata:
  name: user
spec:
  selector:
    matchLabels:
      app: user
  replicas: 2
  template:
    metadata:
      labels:
        app: user
    spec:
      containers:
        - name: user
          image: potato.user.service
          envFrom:
            - configMapRef:
                name: common-env
          env:
            - name: SERVICES
              value: user
写回答

1回答

麦兜搞IT

2021-07-07

您好,没有明白您的意思,什么是“但是编写了yaml后报错”

0
4
麦兜搞IT
回复
DominiY
您好,看你这个报错应该和yaml语法没有关系pull access denied for potato.api.service, repository does not exist or may require ‘docker login’  是你的这台节点无法拉取这个镜像
2021-07-09
共4条回复

系统学习Docker 践行DevOps理念

无论你是开发、测试还是运维,Docker都是你的必备技能。

3297 学习 · 1895 问题

查看课程