How to Containerize multiple files with Docker

10/16/2019

I created a simple application with reactjs/express. The application works as expected after deployment to Google App Engine. I'm attempting to deploy this app to Kubernetes after containerizing with Docker.

my docker file

FROM express-gateway:1.16.9
EXPOSE 8080
COPY server.js .
CMD node server.js

I have multiple files that need to be containerized by Docker, 'server.js' and 'secrets.json' file. In my docker file above I only have server.js, how do I include other files? Also inside server.js i'm using BigQuery which needs to access the additional 'secrets.json' file, how do I specify the path to this json file? In my code i specify the path as follows, will the Docker container work with the following keyFilename?

function query_bigQuery() {          
   const bigqueryClient = new BigQuery({     
      keyFilename: 'secrets.json'
   });
...         
-- Machine Learning
docker
express
google-bigquery
kubernetes
reactjs

1 Answer

10/16/2019

You can copy all required file from the host to docker image and it will able to access other required as same as you are accessing now.

EXPOSE 8080
WORKDIR /app
COPY . .
CMD node server.js

Here copy . . will copy entire files and directories structure form the current context to /app of the docker image.

So I will suggest keeping only desired files in this context ( mean the directory where you place the dockerfile) to keep the image small.

-- Adiii
Source: StackOverflow