skip to Main Content

I’m new to Docker and currently and I’m working on the dokernizing some apps.

Structure of project :

-PlayProject

-------app
----------controllers
----------models
----------views

-------ci
-------conf
-------project

-------public
----------css
----------js
----------img
----------fonts

-------sbt-cache
-------src
-------target

-------front
------------header (npm folder)
------------footer (npm folder)
-------Dockerfile
----*

The project is developed with PlayFramework (with sbt as a build tool) on Backend and Reactjs on front. The front is constritued from gtwo modules (header and footer).

On my dockerfile I need to run build the modules front (run ‘npm run build’ commands in both folders header and footer) to update the public folder before conternizing

My Dockerfile :

FROM openjdk:8

ENV HEADER front/header
ENV FOOTER front/footer
ENV PROJECT_HOME /usr/src
ENV SBT_VERSION 1.2.1

#install node
RUN  
        curl -sL https://deb.nodesource.com/setup_4.x | bash  && 
        # and install node
        apt-get update && 
        apt-get install nodejs && 
        # confirm that it was successful
        node -v && 
        # npm installs automatically
        npm -v

WORKDIR $HEADER/

RUN  
         echo $(ls -1 $HEADER/) && 
        npm cache clean && 
        npm i && 
        npm run build

WORKDIR $FOOTER/

RUN 
        echo $(ls -1 $FOOTER/) && 
        npm cache clean && 
        npm i && 
        npm run build


RUN mkdir -p $PROJECT_HOME/sbt $PROJECT_HOME/app

WORKDIR $PROJECT_HOME/sbt

# Install curl
RUN 
       apt-get update && 
       apt-get -y install curl && 
       apt-get -y install vim

# Install sbt
RUN 
        curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && 
        dpkg -i sbt-$SBT_VERSION.deb && 
        rm sbt-$SBT_VERSION.deb && 
        apt-get update && 
        apt-get -y install sbt


COPY . $PROJECT_HOME/app
WORKDIR $PROJECT_HOME/app

EXPOSE 9000

The issue is that I cannot localize the front folders and run my npm commands. what do you think ?

2

Answers


  1. It looks like you’re not actually sending your local source to the Docker container, so there’s nothing to build.

    Try adding a line like COPY . . before you switch the WORKDIR.

    Login or Signup to reply.
  2. You didn’t set an absolute path to your first WORKDIR instruction :

    The WORKDIR instruction can be used multiple times in a Dockerfile. If a relative path is provided, it will be relative to the path of the previous WORKDIR instruction. For example:

    WORKDIR /a

    WORKDIR b

    WORKDIR c

    RUN pwd

    The output of the final pwd command in this Dockerfile would be /a/b/c.

    quoted from here

    Maybe you want to replace your first WORKDIR like this :

    WORKDIR $PROJECT_HOME/$HEADER
    COPY . .
    # instead of just WORKDIR $HEADER/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search