Home > database >  Docker compose: failing to start container, as it fails to find file, which exists locally
Docker compose: failing to start container, as it fails to find file, which exists locally

Time:02-23

So I am trying to use dokcer compose utility to spin up containers for web app and database.

I have docker-compose.yml file in the same directory, as the app directory, which contains package.json file, so it looks like this (for brevity, rest of files ommited):

- docker-compose.yml
- app/
    - package.json

And the docker compose is pretty basic:

version: "3.7"

services:
    app:
        image: node:12-alpine
        command: sh -c "yarn install && yarn run dev"
        ports:
            - 3000:3000
        working_dir: /app
        volumes:
            - ./:/app
        environment:
            MYSQL_HOST: mysql
            MYSQL_USER: root
            MYSQL_PASSWORD: sa
            MYSQL_DB: todos
            
    mysql:
        image: mysql:latest
        volumes:
            - todo-mysql-data:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: sa
            MYSQL_DATABASE: todos
            
volumes:
    todo-mysql-data:

Then, when I try to run containers with docker-compose up -d command, I see that DB container started successfully, but the web app container cannot start. While inspecting this with docker logs I see log:

Couldn't find a package.json file in "/app"

As I am totally new to docker and docker compose, I don't really know where exactly it's defined and how to solve it.

Seems very basic and simple though...

CodePudding user response:

Assuming that you upload from the top level directory as listed below:

- docker-compose.yml
- app/
    - package.json

you are mounting in your directory contents as defined here:

        volumes:
            - ./:/app

This in turn results in the /app directory containing the app directory, so it will look like /app/app/package.json.

you can fix this by adjusting the volume mount like so:

        volumes:
            - ./app/:/app
  • Related