I have the following docker-compose.yml:
version: '3'
services:
frontend:
build:
context: ./
dockerfile: docker/Dockerfile
image: tsl.web.frontend.image
container_name: tsl.web.frontend.container
ports:
- "8080:80"
Notice the context: ./
And this is my docker-compose command:
docker-compose build --force-rm --build-arg ENVIRONMENT=development frontend
Here is the structure of my src code:
Notice I have red underlined two important aspects of this structure.
Now here is a part of my Dockerfile, I will include the entire Dockerfile below:
# https://stackoverflow.com/a/35774741/1258525
# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
COPY ./package.json /tmp/package.json
RUN npm --prefix /tmp install /tmp
RUN cp -rn /tmp/node_modules ./
#RUN npm --prefix ./ run build-development ./
RUN npm run build-development #failing here
COPY dist /usr/share/nginx/html
So the RUN npm run build-development
command is failing because it cannot find package.json:
This is where I am confused about the execution context of the RUN
statement. I was able to copy the package.json file to /tmp in the previous Dockerfile command COPY ./package.json /tmp/package.json
. I think my context is still where my docker-compose.yml file lives but obviously it is not...
Complete Dockerfile:
FROM centos:7
MAINTAINER Brian Ogden
# Not currently being used but may come in handy
ARG ENVIRONMENT
ENV NODE_VERSION 6.11.1
RUN yum -y update; yum clean all
RUN yum -y install http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm; yum -y makecache
RUN yum -y install nginx-1.12.0
# Cleanup some default NGINX configuration files we don’t need
RUN rm /etc/nginx/conf.d/default.conf
COPY ./docker/conf/frontend.conf /etc/nginx/conf.d/frontend.conf
COPY ./docker/conf/nginx.conf /etc/nginx/nginx.conf
#############################################
# NodeJs Install
#############################################
RUN yum install -y \
wget
#Download NodeJs package
RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz
#extract the binary package into our system's local package hierarchy with the tar command.
#The archive is packaged within a versioned directory, which we can get rid of by passing the --strip-components 1 option.
#We will specify the target directory of our command with the -C command:
#This will install all of the components within the /usr/local branch
RUN tar --strip-components 1 -xzvf node-v* -C /usr/local
#############################################
# https://stackoverflow.com/a/35774741/1258525
# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
COPY ./package.json /tmp/package.json
RUN npm --prefix /tmp install /tmp
RUN cp -rn /tmp/node_modules ./
#RUN npm --prefix ./ run build-development ./
RUN npm run build-development
COPY dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx"]