Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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…

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading