Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker stack deploy: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: image reference must be provided

I'm trying to deploy an app with docker stack. After building and testing with docker-compose (which have run perfectly ok), I created a swarm, joined it and tried to run

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

The following error occured:

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

Here is my 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

I'm using Docker version 19.03.8, build afacb8b and docker-compose version 1.25.4, build 8d51620a

like image 398
Hoàng Tùng Avatar asked Jun 13 '26 05:06

Hoàng Tùng


1 Answers

When you run the docker stack deploy from the compose file. You need to mention the image name as well when building it from Dockerfile.

Please refer the below 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

like image 53
nischay goyal Avatar answered Jun 17 '26 00:06

nischay goyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!