Akash Yadav
Akash Yadav

Reputation: 1

Docker Compose Failing for command

Dockerfile:

FROM hseeberger/scala-sbt:8u222_1.3.5_2.13.1
WORKDIR /code/SimpleStocks
COPY ./SimpleStocks .
RUN sbt dist
WORKDIR /code/SimpleStocks/target/universal
RUN unzip simplestocks-0.0.1.zip
WORKDIR /code/SimpleStocks/target/universal/simplestocks-0.0.1
CMD ["bin/simplestocks"]

docker-compose.yml:

version: "3.7"
services:
  app:
    container_name: simple-stocks
    image: simple-stocks:1.0.0
    build: .
    ports:
      - '9000:9000'
    volumes:
      - .:/code
    links:
      - pgdb1
  pgdb1:
    image: postgres
    environment:
      POSTGRES_DB: simple_stocks
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - pgdb1data:/var/lib/postgresql/data/
      - ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
    ports:
      - '5432:5432'
volumes:
  pgdb1data:

When I manually run simple-stocks container using docker run -it {imageId}, I am able to run it successfully; but, on doing docker compose up I am receiving:

Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "bin/simplestocks": stat bin/simplestocks: no such file or directory: unknown

Upvotes: 0

Views: 1413

Answers (1)

David Maze
David Maze

Reputation: 159761

Your Dockerfile is building the application in /code/SimpleStocks/target/universal/simplestocks-0.0.1, but then your Compose file bind-mounts a host directory over /code, which hides everything the Dockerfile does. The bind mount is unnecessary and deleting it will resolve this issue.

Bind-mounting a host directory over your entire built application usually is not a best practice. I most often see it trying to convince Docker to emulate a local development environment, but even that approach doesn't make sense for a compiled language like Scala.

You can safely remove the volumes: block. The obsolete links: can also be removed. You don't need to manually specify container_name:, nor do you need to specify both build: and image: unless you're planning to push the built image to a registry. That would reduce the Compose setup to just:

version: '3.8'
services:
  app:
    build: .
    ports:
      - '9000:9000'
  pgdb1: (as in the question originally)
volumes:
  pgdb1data:

Upvotes: 1

Related Questions