请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

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

老师,请教一下,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

正在回答 回答被采纳积分+3

1回答

麦兜搞IT 2021-07-07 15:13:00

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

0 回复 有任何疑惑可以回复我~
  • 提问者 DominiY #1
    项目中有两个文件:
    - docker-compose.yml
    - k8s.yaml
    当在本地docker-compose up --build -d时,可以正常运行
    使用kubtcl create -f k8s.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’
    
    问题:yaml改如何配置?教程中似乎没有讲到docker与k8s的配合开发
    回复 有任何疑惑可以回复我~ 2021-07-07 15:29:49
  • 麦兜搞IT 回复 提问者 DominiY #2
    您好,不太清楚您的具体环境是什么样的,您确认在k8s节点上能拉取这个image么 potato.api.service
    回复 有任何疑惑可以回复我~ 2021-07-08 03:18:06
  • 提问者 DominiY 回复 麦兜搞IT #3
    已解决,k8s需要docker login,设置imagePullPolicy: Always
    回复 有任何疑惑可以回复我~ 2021-07-08 15:43:41
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信