Why don't I get access to the React application inside Docker? - reactjs

I executed npm run build and created a react build then I build a Docker image with the Docker file.
FROM node:12.2.0-alpine
COPY build ./
RUN ["npm", "install", "-g", "serve"]
CMD ["serve", "-s", "build"]
I run this docker image with the command:
docker run -ip 5000:5000 steinko/testreacttutorial:1
Then I got the message:
INFO: Accepting connections at http://localhost:5000
When I enter localhost:5000 in the browser I get the following:
404 Request path could not be found
How do I fix this error?

please check the docker inspect command output for your image to find the application port exposed and then map that to 5000 port in the docker run command

Related

Front-end application with yarn starting locally but when docker container is run ports are empty

The port loads and I can view the app locally on port 3000. I can do this by running yarn the yarn start. The container runs and says it can be
Available on:
http://127.0.0.1:3000
http://172.17.0.2:3000
When loading the ports in my browser I see nothing. This is error is occurring with two projects I am working on.
For reference these are the front-ends I am trying to place in images.
https://github.com/Uniswap/interface/
https://github.com/safe-global/web-core
I am running node v18.12.1
The DockerFile
FROM node:16-alpine
RUN apk add --no-cache libc6-compat git python3 py3-pip make g++
WORKDIR /app
COPY . .
# install deps
RUN yarn
ENV NODE_ENV production
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
EXPOSE 3000
ENV PORT 3000
CMD [ "yarn", "start" ]
I am able to get the images to say they compiled all the code and run locally. I was expected these apps then to load on port 3000 like they do when I run it locally but this only results in an error in the browser stating "this site can't be reached"
Port 3000 its port inside container. You have to expose port.
For example:
-p 3000:80
And open outside port 80.
https://docs.docker.com/config/containers/container-networking/

Connection refused error between react and spring boot in a docker environment

I'm trying to run a full stack application of React JS and Spring Boot in my docker environment. Locally everything works fine. But inside the docker environment, the react js and spring boot application both starts. But I'm getting a connection refused error when I'm trying to establish communication between react and spring boot.
I've added a ProxyPass in my apache2 config file inside the docker environment as follows :-
ProxyPass /app-name/ http://0.0.0.0:9090/
Error :- OPTIONS http://localhost:8080/login net::ERR_CONNECTION_REFUSED.
Docker commands used :-
Docker command to build the docker image :-
docker build --rm -t <image-name>.
I've exposed the ports required in the docker run command as follows :-
docker run --rm -p 5050:8080 -p 6060:3000 --name <container-name> <image-name>
Docker command to exec inside the container :-
docker exec -it <container-name> /bin/bash
Inside the docker environment, I started the spring boot application using
mvn spring-boot:run and started the react application using yarn install followed by yarn start
How do I solve the connection refused error here?
As per comment ERR_CONNECTION_REFUSED is shown because you are exposing port 5050 on the host and not 8080.
Using http://localhost:5050 will work or you can run the docker command and expose the port on the host as 8080 too
docker run --rm -p 8080:8080 -p 6060:3000 --name <container-name> <image-name>
If you are using separate containers for react app and spring boot app run docker inspect and be shure you are pointing to the Ip address of the container and not to localhost

Why does docker run do nothing when i try to run my app?

I made a website to React and I'm trying to deploy it to an Nginx server by using Docker. My Dockerfile is in the root folder of my project and looks like this:
FROM tiangolo/node-frontend:10 as build-stage
WORKDIR /app
COPY . ./
RUN yarn run build
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx:1.15
COPY --from=build-stage /app/build/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
When I run docker build -t mywebsite . on the docker terminal I receive a small warning that I'm building a docker image from windows against a non-windows Docker host but that doesn't seem to be a problem.
However, when I run docker run mywebsite nothing happens, at all.
In case it's necessary, my project website is hosted on GitHub: https://github.com/rgomez96/Tecnolab
What are you expecting ? Nothing will happen on the console except the nginx log.
You should see something happening if you go to http:ip_of_your_container.
Otherwise, you can just launch your container with this command :
docker container run -d -p 80:80 mywebsite
With this command you'll be able to connect to your nginx at this address http://localhost as you are forwarding all traffic from the port 80 of your container to the port 80 of your host.

Build the docker with react app throws error

Create the scratch react application using "create-react-app docker-build" then try to build the docker image for it with below docker script but it throws error when try to run that docker image.
Docker version have used: Docker version 18.09.0, build 4d60db4
Simply follow the steps in below post for docker exploration with react app but i end up with error like below
Reference : https://medium.com/#shakyShane/lets-talk-about-docker-artifacts-27454560384f
Step 1:
Build the docker image success.
docker build -t testwebapp .
Step 2:
Run the that image with below command
docker run -p 8080:80 testwebapp:latest
Docker script used:
FROM node:10.9 as build-deps
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build
FROM nginx:1.12-alpine
COPY - from=build-deps /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Error log:
docker: Error response from daemon: driver failed programming external connectivity on endpoint festive_margulis (71686edb7753ec2fdf019ef4cfcf0e95476e1fb7c2368084feb17fd2551fcf45): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:8080:tcp:172.17.0.3:80: input/output error.
Usually, this is a problem with the Docker engine.
service docker restart
If you are working with Windows you have to specify the ip address like
docker run -ip 127.0.0.1 -p 8080:80 testwebapp:latest
And usually for me i have to restart the docker on windows after pc start twice then works everything as it should

docker executable file not found in $PATH" react image

I am trying to run a freshly create react app made with create-react-app in docker. I have a Docker file which succesfully allows me to build the image, but when I try to run it I get:
PS C:\Users\Bertinator\desktop\gamelist\client> docker run client4 .
container_linux.go:265: starting container process caused "exec: \".\":
executable file not found in $PATH"
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from
daemon: oci runtime error: container_linux.go:265: starting container
process caused "exec: \".\": executable file not found in $PATH".
ERRO[0001] error waiting for container: context canceled
PS C:\Users\Bertinator\desktop\gamelist\client>
This is my Docker file, which is place in the root folder of my create-react-app project:
FROM node:7.8.0
ENV NPM_CONFIG_LOGLEVEL warn
COPY . .
RUN npm run build --production
RUN npm install -g serve
CMD serve -s build
EXPOSE 5000
Are you running from a Linux docker image on a Windows machine? That does not work.
Ref http://training.play-with-docker.com/beginner-linux/
(...) Linux containers require the Docker host to be running a Linux kernel. For example, Linux containers cannot run directly on Windows Docker hosts. The same is true of Windows containers - they need to run on a Docker host with a Windows kernel.
When you say docker run client4 . you are asking docker to run that container and execute the . (dot) command which does not make sense. That is why you are getting the first error.

Resources