TL:DR - I am trying to deploy my MERN stack application to GCP's Cloud Run. Struggling with what I believe is a port issue.
My React application is in a client folder inside of my Node.js application.
Here is my one Dockerfile to run both the front-end and back-end:
FROM node:13.12.0-alpine
WORKDIR /app
COPY . ./
# Installing components for be connector
RUN npm install --silent
WORKDIR /app/client
RUN npm install --silent
WORKDIR /app
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT [ "/app/entrypoint.sh" ]
... and here is my entrypoint.sh file:
#!/bin/sh
node /app/index.js &
cd /app/client
npm start
docker-compose up works locally, and docker run -p 8080:8080 -p 3000:3000 <image_id> runs the image I built. Port 8080 is for Node and port 3000 for the React app. However, on Cloud Run, the app does not work. When I visit the app deployed to Cloud Run, the frontend initially loads for a split second, but then the app crashes as it attempts to make requests to the API.
In the Advanced Settings, there is a container port which defaults to 8080. I've tried changing this to 3000, but neither works. I cannot enter 8080,3000, as the field takes valid integers only for the port. Is it possible to deploy React + Node at the same time to Cloud Run like this? How can I have Cloud Run listen on both 8080 and 3000, as opposed to just 1 of the 2?
Thanks!
It's not currently possible.
Instead, you can run multiple processes inside Cloud Run, but instead use nginx to proxy requests between them depending on the URL, similar to what's recommended in this answer.
Related
I faced some teething issue when trying to deploy my Docker image which contains a simple streamlit app to Heroku. My issue is that I am unable to access my Docker after deployment. On closer look, I discovered the following error:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I had researched and understood that this is because the port is unavailable, since Heroku will dynamically assign port number.
I had made sure that this will not happen by putting the following my Dockerfile.
Dockerfile:
FROM python:3.7
COPY . /app
WORKDIR /app
RUN pip install streamlit
ENTRYPOINT ["streamlit","run", "--server.enableCORS", "false" ,"--server.port", "$PORT"]
CMD ["app.py"]
I am now able to see that the Network URL and External URL port number are assigned by Heroku as it is not the typical 5901 number.
What puzzled me, however, is why is the container unable to bind to the given dynamic port number? I thought the app would be using the given dynamic number?
The problem is that $PORT does not get replaced with the corresponding environment variable when the Docker run is executed on the Heroku Docker Registry.
An alternative is to create a Docker file which invokes .sh script
FROM python:3.7
COPY . /app
WORKDIR /app
RUN pip install streamlit
ENTRYPOINT "/startup.sh"
and the startup.sh
echo PORT $PORT
streamlit run --server.enableCORS false --server.port $PORT app.py
I created a simple VueJS app with a very basic configuration. I used the webpack configuration to do this.
vue init webpack app
I build this simple Dockerfile
FROM node:lts-alpine
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
# install project dependencies
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN npm run build
EXPOSE 3838
CMD [ "http-server", "dist" ]
This app should run of a plattform which only listens to port 3838. Changing the Dockerfile to EXPOSE 3838 did not work unfortunately.
sudo docker run -it -p 3838:3838 vuetest
Starting up http-server, serving dist
Available on:
http://127.0.0.1:8080
The container runs, but stil on 8080.
I´m quite unfamiliar with both VueJS and deploying, so can anyone help me? I guess the configuration to listen to 8080 might be set in a different file and the Dockerfile ignores it.
Your application server runs by default on 8080
https://www.npmjs.com/package/http-server
Use flag -p 3838 to serve on that port.
Docker is doing its job correctly, adjust in your CMD
CMD [ "http-server", "-p 3838", "dist" ]
You can try just use the port 8080 of the continer and map it to port 3838 of your host.
#Dockerfile: delete the line -> Expose 3838
#Command line : $ sudo docker run -it -p 3838:8080 vuetest
This is an option not to add more lines to the Dockerfile.
Bye
I'm new at docker and I want to make an image of my node.js api and webapp.
I'm on Windows.
I tried following in my Dockerfile and then execute these commands but nothing happens.
Container runs well but I can't reached my webapp on localhost:8080
docker run -d -p 8080:8080 web3-webapp-image
FROM node:10
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
Your node application must also be listening to the same port that is being exposed.
If your app is listening to port 3000 and you're publishing port 8080, then your app isn't going to be able to open up communication back to your localhost.
You can fix this by either publishing the same port the node app is listening on, or change the port your node app is listening to.
Thank's problem is solved. App was listening on port 3000 et I was not publishing on the same port.
I've created an image using this Docker file...
FROM node:8
# Create application directory
WORKDIR /usr/src/app
# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well.
# If dev dependencies have been set, use --only-production when deploying to production
# Bundle app source code
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
But when I run it using $ docker run -d --rm -p 3000:3000 62 I can't cUrl the API running inside the container from the Docker host (OS X) using curl http://localhost:3000/About
If I exec into the container I get a valid response from the API via cUrl. Looks like a Linux firewall in the container but I don't see one running.
any ideas?
Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1
I am totally new to docker and the client I am working for have sent me dockerfile configuration .dockerignore file probably to set up the work environment.
So this is basically what he sent to me
FROM node:8
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY assets ./assets
COPY server ./server
COPY docs ./docs
COPY internals ./internals
COPY track ./track
RUN npm run build:dll
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
with docker build and run command (he also provided the same)
docker build -t reponame:tag .
docker run -p 3000:3000 admin-web:v1
Here, First can someone tell me what does copy . . mean?
He asked me to configure all the ports accordingly. From going through videos, I remember that we can map ports like this -p 3000:3000 but what does configuring port means? and how can i do? any relevant article for the same would also be helpful. Do I need to make docker-compose file?
. is current directory in linux. So basicly: copy current local directory to the current container's directory.
The switch -p is used to configure port mapping. -p 2900:3000 means publish your local port 2900 to container's 3000 port so that the container is available on the outside (by your web browser for instance). Without that mapping the port would not be available to access outside the container. This port is still available to other containers inside same docker network though.
You don't need to make a docker-compose.yml file, but it certainly will make your life easier if you have one, because then you can just run docker-compose up every time to run the container instead of having to run
docker run -p 3000:3000 admin-web:v1
every time you want to start your applicaton.
Btw here is one of the ultimate docker cheatsheets that I got from a friend, might help you: https://gist.github.com/ruanbekker/4e8e4ca9b82b103973eaaea4ac81aa5f