Docker堆栈部署:来自守护程序的错误响应:rpc错误:代码= InvalidArgument desc = ContainerSpec:必须提供图像引用

问题描述 投票:0回答:1

我正在尝试使用docker stack部署应用。在使用docker-compose进行构建和测试(已经运行perfectly ok)之后,我创建了一大群,加入其中并尝试运行

docker stack deploy --compose-file docker-compose.yml default

发生以下错误:

failed to create service default_sharkcop-api: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: image reference must be provided

这是我的docker-compose.yml

version: "3"
services:
  # Define the api web application
  sharkcop-api:
    # Build the Dockerfile that is in the web directory
    build: 
      context: ./sharkcop-api
      dockerfile: Dockerfile
    # Always restart the container regardless of the exit status; try and restart the container indefinitely
    restart: always

    # Expose port 8000 to other containers (not to the host of the machine)
    expose:
      - "8080"

    # Link the containers together so they can talk to one another
    links:
      - redis

    # Pass environment variables to the flask container (this debug level lets you see more useful information)
    environment:
      port: 8080
      REDIS_URL: redis://cache

    # Deploy with three replicas in the case one of the containers fails (only in Docker Swarm)
    deploy:
      mode: replicated
      replicas: 3

  # Define the NGINX forward proxy container
  nginx:
    # build the nginx Dockerfile
    build: 
      context: ./reverse-proxy
      dockerfile: Dockerfile

    restart: always

    # Expose port 80 to the host machine
    ports:
      - "80:80"
    deploy:
      mode: replicated
      replicas: 3

    # The application needs to be available for NGINX to make successful proxy requests
    depends_on:
      - sharkcop-api

  # Define the sharkcop-webinspector
  sharkcop-webinspector:
    build: 
      context: ./sharkcop-webinspector
      dockerfile: Dockerfile
    restart: always

    expose:
      - "8080"

    # Mount the web directory within the container at /app/sharkcop-webinspector
    volumes:
      - ./sharkcop-webinspector:/app/sharkcop-webinspector

    links:
      - sharkcop-api

    deploy:
      mode: replicated
      replicas: 3

  redis:
    image: redis
    container_name: cache
    command: ["redis-server", "--appendonly", "yes"]
    restart: always
    expose:
      - 6379
    volumes:
      - ./data/redis:/data

我正在使用Docker 19.03.8版,内部版本afacb8bdocker-compose版本1.25.4,内部版本8d51620a

docker docker-compose docker-swarm
1个回答
0
投票

当您从撰写文件运行docker stack deploy时。从Dockerfile构建它时,还需要提及image名称。

请参阅下面的docker-compose.yaml

version: "3"
services:
  # Define the api web application
  sharkcop-api:
    # Build the Dockerfile that is in the web directory
    build:
      image: sharcop-api
      context: ./sharkcop-api
      dockerfile: Dockerfile
    # Always restart the container regardless of the exit status; try and restart the container indefinitely
    restart: always

    # Expose port 8000 to other containers (not to the host of the machine)
    expose:
      - "8080"

    # Link the containers together so they can talk to one another
    links:
      - redis

    # Pass environment variables to the flask container (this debug level lets you see more useful information)
    environment:
      port: 8080
      REDIS_URL: redis://cache

    # Deploy with three replicas in the case one of the containers fails (only in Docker Swarm)
    deploy:
      mode: replicated
      replicas: 3

  # Define the NGINX forward proxy container
  nginx:
    # build the nginx Dockerfile
    build: 
      image: nginx-proxy
      context: ./reverse-proxy
      dockerfile: Dockerfile

    restart: always

    # Expose port 80 to the host machine
    ports:
      - "80:80"
    deploy:
      mode: replicated
      replicas: 3

    # The application needs to be available for NGINX to make successful proxy requests
    depends_on:
      - sharkcop-api

  # Define the sharkcop-webinspector
  sharkcop-webinspector:
    build: 
      context: ./sharkcop-webinspector
      dockerfile: Dockerfile
    restart: always

    expose:
      - "8080"

    # Mount the web directory within the container at /app/sharkcop-webinspector
    volumes:
      - ./sharkcop-webinspector:/app/sharkcop-webinspector

    links:
      - sharkcop-api

    deploy:
      mode: replicated
      replicas: 3

  redis:
    image: redis
    container_name: cache
    command: ["redis-server", "--appendonly", "yes"]
    restart: always
    expose:
      - 6379
    volumes:
      - ./data/redis:/data

© www.soinside.com 2019 - 2024. All rights reserved.