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

Hoà*_*ùng 1 docker docker-compose docker-swarm

我正在尝试使用 docker 堆栈部署应用程序。建立与泊坞窗,撰写(已运行测试后完全确定),我创建了一个群,加入它,并试图逃跑

docker stack deploy --compose-file docker-compose.yml default
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

failed to create service default_sharkcop-api: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: image reference must be provided
Run Code Online (Sandbox Code Playgroud)

这是我的 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

Run Code Online (Sandbox Code Playgroud)

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

nis*_*yal 5

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

请参考以下 docker-compose.yaml

version: "3"
services:
  # Define the api web application
  sharkcop-api:
    # Build the Dockerfile that is in the web directory
    image: sharcop-api
    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
    image: nginx-proxy
    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

Run Code Online (Sandbox Code Playgroud)

  • docker-compose 专为单主机部署而设计。构建映像所需的所有详细信息都存在于主机上。这就是构建和部署周期可用于 docker-compose 的原因。Swarm 专为多节点部署而设计,因此期望镜像在镜像注册表中可用。构建和部署生命周期是分离的。养成在 compose 文件参考中查找配置项的习惯很有帮助:https://docs.docker.com/compose/compose-file/#build。 (3认同)