'docker-compose build image or build context [closed]

I would like build custom Dockerfile, but i've this message : --> Starting build app ERROR: The Compose file is invalid because: Service app has neither an image nor a build context specified. At least one must be provided.

I don't understand why the name is app. You can see my docker-compose.yml file :

version: "3"

services:
  webapp-react:
    build:
      context: ./docker/nodejs
      dockerfile: Dockerfile
    image: webapp/react
    container_name: webapp_react
    user: ${UID}:${GID}
    environment:
      - NODE_ENV=build

  webapp-nginx:
    build:
      context: ./docker/nginx
      dockerfile: Dockerfile
    image: webapp/nginx
    container_name: webapp_nginx
    environment:
      - VIRTUAL_HOST=${SITE_URL}
      - VIRTUAL_PORT=8080
      - VIRTUAL_NETWORK=nginx-proxy
      - LETSENCRYPT_HOST=${SITE_URL}
      - LETSENCRYPT_EMAIL=${MAILER_DEFAUT_SENDER_ADDRESS}
    ports:
      - "8181:80"
    volumes:
      - ./app/build:/www-data/

networks:
  default:
    external:
      name: nginx-proxy

Anyone know where did I make an error ?

Thank you !



Solution 1:[1]

In my case, I had renamed the services in the docker-compose.yml file, but forgot to do the same in docker-compose.override.yml and docker-compose.vs.release.yml.

Solution 2:[2]

The below applies everywhere that docker-compose is used. I use visual studio docker tools as reference

Quick answer:

I would thoroughly look at my docker-compose.override.yml files for references of the defined service in the error description. Then delete it. The error mentions that you have a service that is defined in the override file but not on the base docker-compose file.

Reproduce the problem with visual studio.

I came across the same issue with my docker-compose.

Visual studio also populates docker-compose.override.yml by default. When you append services.

Like @Jorn.Beyers mentioned this can be easily replicated if you are using docker tools for visual studio. Append some services run your docker-compose and afterward start removing services or services from your docker-compose.yml.

The OP's descriptive error will appear.

I am not sure if you clean the solution with visual studio you get rid of this problem. It did not work for me.

What I did and solved the problem?

What I did was I located the place where docker-compose is. I found that there is a docker-compose.override.yml. Which still references the service I deleted.

So what I did was locate the service inside my docker-compose.override.yml. In the below case I still reference sth.blog.api.

sth.blog.api:
environment:
  - ASPNETCORE_ENVIRONMENT=Development
  - ASPNETCORE_URLS=https://+:443;http://+:80
ports:
  - "80"
  - "443"
volumes:
  - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
  - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

Looked similar to the above. After I deleted these lines. I restarted docker-compose and everything runs.

Note

Since I use visual studio and its magical auto-gen tools. Which I guess is where this error mostly appears and can be intimidating, since especially for beginners, the error description gives you the above error and when clicking on the error takes you to a very strange file and not at the source of the problem.

More info about container tool inside visual studio: https://docs.microsoft.com/en-us/visualstudio/containers/?view=vs-2019

Solution 3:[3]

I got the same issue when I was removing some applications from the docker-compose and docker-compose-override file in Visual Studio 2019. Cleaning the solution before running docker-compose again did work for me.

Solution 4:[4]

In my case, i added service in docker-compose.override.yml file, but forgot to add it into docker-compose.yml file.

Solution 5:[5]

If you happen to see this error while using VSCode's DevContainer, just delete your .devcontainer folder and autogenerate a new one.

Solution 6:[6]

Make sure your docker-compose is running the right version. Example: my docker-compose was on version 2.0.1 but in the documentation the latest one is 1.29.2. So, I had to downgrade to the latest version (lol).

Solution 7:[7]

I had a similar issue. I did a combination of 2 possible ways of fixing it.

  1. I copied the desired code from docker-compose.yml and paste it to docker-compose.override.yml, so that both codes to be the same.
  2. Then I have just cleaned the solution and finally I run "docker-compose up".

After that it started generating an image in Docker. I hope this will help to anyone with a similar case.

Solution 8:[8]

It seems you like you made some changes and didn't rebuild the image.

So yes, clean all but also, - clean docker-compose - rebuild docker-compose

Solution 9:[9]

Not sure why that occurred with you, but once I've faced a problem like that, I've solved this by that way.

goto your $user directory find .docker inside .docker directory you find config.json

then delete the portion of credHelpers

"credHelpers":{"gcr.io":"gcloud","us.gcr.io":"gcloud","eu.gcr.io":"gcloud","asia.gcr.io":"gcloud","staging-k8s.gcr.io":"gcloud","marketplace.gcr.io":"gcloud"},

Then restart docker. Hope it will fix your problem.

Solution 10:[10]

What worked for me is to clean and then rebuild the project.