Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose build image or build context

Tags:

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 !

like image 241
Stéphane R. Avatar asked Sep 11 '18 20:09

Stéphane R.


4 Answers

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.

like image 154
adam0101 Avatar answered Sep 19 '22 11:09

adam0101


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

like image 31
panoskarajohn Avatar answered Sep 21 '22 11:09

panoskarajohn


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.

like image 38
Jorn.Beyers Avatar answered Sep 20 '22 11:09

Jorn.Beyers


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

like image 21
So_oP Avatar answered Sep 21 '22 11:09

So_oP