skip to Main Content

I am trying to deploy a personal project on my personal Fedora server. This is the docker-compose.yml:

version: '3.7'
services:
  postgres:
    image: postgres:latest
    container_name: db
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: 1234
      POSTGRES_DB: TESAF
    ports:
      - "9111:5432"
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "TESAF"]
  java:
    image: openjdk:19
    container_name: backend
    build: .
    ports:
      - "8080:8080"
    volumes:
      - ./backend:/app
    command: ["java", "-jar", "/app/TESAF-0.0.1-SNAPSHOT.jar"]
    depends_on:
      postgres:
        condition: service_healthy
  apache:
    image: httpd
    container_name: frontend
    ports:
      - "3000:80"
      - "4443:443"
    volumes:
      - ./frontend:/usr/local/apache2/htdocs

The backend folder contains the jar file from the spring application, after building with maven. The frontend folder is the "build" folder produced by react after running npm run build. On my MacBook it works fine, yet, when I try to run sudo docker-compose up(it gives permissions error without sudo and without the hyphen it says 'compose' is not a docker command), it gives the following output:

Status: Downloaded newer image for postgres:latest
Building java
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/antoniu/tesaf-deploy/Dockerfile: no such file or directory
ERROR: Service 'java' failed to build : Build failed

Why does it try to access a Dockerfile that does not exist and is never specified? Is it because I tried running with docker-compose, rather than docker compose? If so, what can I do for it to recognize docker compose?

File structure:

./docker-compose.yml
./frontend/<the contents of the build folder or react>
./backend/<the contents of the target folder from maven>

Thank you

2

Answers


  1. From the docs:

    When a build subsection is present for a service, Compose ignores the image attribute for the corresponding service, as Compose can build an image from source.

    Since you have specified build subsection, docker compose tries to build from the source. To do this, it searches the context folder, ., for a Dockerfile, but fails.

    Login or Signup to reply.
  2. Try removing the

    build .
    

    from the java service in your docker compose file. I believe it is looking for the dockerfile inside your directory because of that.

    The docker compose command is: docker-compose and not docker compose

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search