Deploy reactjs application on the container instance - azure

I am very new to this Containers, so I am unable to deploy the application on the Container instance .
I tried below steps but i could not resolve the issue. Please help me out of this. Thanks in advance
steps:
1.I have created the Reactjs build.
2.Created the docker image and Create the container registry and pushed it into docker container instance.
my Docker file is :
FROM nginx: version
copy /build/user/share/nginx/html
I have created the docker image and build that image and successfully created the docker image
I have created the container rgistry and when I trying to push the docker image to container instance after that i am not able to access the application using web.
docker build -t image_name
Can anyone help me that how to access the application through UI
Thanks in Advance!

I tried to reproduce the same issue in my environment and got the below results
I have created and build the npm using below command
npm run build
I have created example docker file and run the file
#docker build -t image_name
FROM node:16.13.1-alpine as build
WORKDIR /app
ENV PATH /app/node/_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm install react-scripts -g --silent
COPY . ./
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx","-g","daemon off"]
I have created the container registry
Enabled the access to to push the image to container registry
I have logged into the container registry using login server credentials
docker login server_name
username:XXXX
password:XXXXX
I have tagged and pushed the image into container registry
docker tag image_name login-server/image
docker push login-server/image_name
I have created the container instances to deploy the container image
While creating in Networking i have given the DNS label and created
By using FQDN link I can able to access the image through UI

Related

Docker container bound to local volume doesn't update

I created a new docker container for a Node.js app.
My Dockerfile is:
FROM node:14
# app directory
WORKDIR /home/my-username/my-proj-name
# Install app dependencies
COPY package*.json ./
RUN npm install
# bundle app source
COPY . .
EXPOSE 3016
CMD ["node", "src/app.js"]
After this I ran:
docker build . -t my-username/node-web-app
Then I ran: docker run -p 8160:3016 -d -v /home/my-username/my-proj-name:/my-proj-name my-username/node-web-app
The app is successfully hosted at my-public-ip:8160.
However, any changes I make on my server do not propagate to the docker container. For example, if I touch test.txt in my server, I will not be able GET /test.txt online or see it in the container. The only way I can make changes is to rebuild the image, which is quite tedious.
Did I miss something here when binding the volume or something? How can I make it so that the changes I make locally also appear in the container?

How to add files on application path while creating docker image

I have deployed a http trigger function in Azure Kubernetes Service. I need some files that has to be kept on application path. How to add those files while creating the docker image..
steps I have followed
created a http trigger function on local
created docker image of that function
pushed the docker image in azure portal
deploying it in AKS
here is my file structure:
[1]: https://i.stack.imgur.com/jkLLO.png
here is my docker file:
[2]: https://i.stack.imgur.com/hE4Ny.png
myfirstfunc folder contains the index.js and function.json files. I have to add the music.mp3 and thankyou.mp4 files in my docker container..
my docker file:
FROM mcr.microsoft.com/azure-functions/node:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot
COPY package*.json ./
RUN npm install

Docker buildx with node app on Apple M1 Silicon - standard_init_linux.go:211: exec user process caused "exec format error

Please help!
I am trying to deploy a docker image to a kuebernetes clusters. No problem until I switched to new Macbook Pro with M1.
Once I build the image on the m1 machine and deploy I get the following error from the kuebernetes pod:
standard_init_linux.go:211: exec user process caused "exec format error"
After doing some research, I followed this medium post on getting docker buildx added and set up.
Once I build a new image using the new buildx and run it locally using the docker desktop (the m1 compatible preview version), it runs without issue. However the kubernetes pod still shows the same error.
standard_init_linux.go:211: exec user process caused "exec format error"
My build command
docker buildx use m1_builder && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -f Dockerfile -t ${myDockerRepo} --push . '
During the build I see each platform logging out that it is running the commands from my Dockerfile.
My push command
docker push ${myDockerRepo}
One odd thing to note is the sha256 digest in the docker push command response does not change.
Here is my docker file:
# Use an official Node runtime as a parent image
FROM node:10-alpine
# Copy the current directory contents into the container at /app
COPY dist /app
# Set the working directory to /app
WORKDIR /app
# Make port 8000 available to the world outside this container
EXPOSE 8000
# Run npm run serve:dynamic when the container launches
CMD ["node", "server"]
I am no docker expert, clearly.
Started with a full head of hair. Down to 3 strands. Please save those 3 strands.
I appreciate all help and advice!
Update
I have pulled the image built by the M1 macbook down to my other macbook and could run the image locally via docker desktop. I am not sure what this means. Could it be just a kuebernetes setting?
Try adding --platform=linux/amd64 to your dockerfile:
FROM --platform=linux/amd64 node:10-alpine

How to specify Docker private registry credentials in Docker configuration File?

I am creating Docker container of nodejs application. Below is the sample of my Docker configuration file
FROM node:6.11
WORKDIR /usr/src/app
COPY package.json .
npm install
copy . /usr/src/app
EXPOSE 80
CMD [ "npm", "start" ]
This will download the node image from Docker hub and then it will create Docker image as per the configuration.
For security reasons I don't want to download nodejs image from Docker hub, Instead I want to use my private repository to download nodejs image.
As I have setup private repository I am not sure how to specify registry credentials in DockerFile.
Can anyone help me with this?
By default, docker pulls all images from Dockerhub. If you want to pull an image from another registry, you have to prefix the image name with the registry URL. Check the official docker pull documentation.
In your case, you have 2 options:
The first is to specify explicitly the registry inside the Dockerfile as such:
FROM <registry>:<port>/node:6.11
WORKDIR /usr/src/app
Once you build, the image will be downloaded from the private registry. Make sure that you are logged in to the registry before building using the docker login command.
Alternatively, if you don't want to change the docker file. Pull the image from the private registry using docker pull <registry>:<port>/node:6.11 and then force docker build to use this image by tagging it with only node:6.11
docker tag <registry>:<port>/node:6.11 node:6.11
Before you build the Docker image you'll have to do docker login to your private repo. Then pulls - explicit or implicit through FROM will use that registry (and while I can't find any documentation to back that up, I suspect it also fallback to Docker Hub if it can't find the image there, but that may be dependent on the registry settings????)
I guess you already have nodejs image in your local docker registry.
If you want to pull the nodejs image from local docker registry:
Make sure your docker daemon is pointing to local docker registry use --insecure-registry <registry_address>:<port> as mentioned here https://docs.docker.com/engine/reference/commandline/dockerd/
Change Dockerfile to point to image in registry. FROM <registry_address>:<port>/node:6.11 (actually this will be the complete name of your nodejs image in local docker registry)
The registry credentials can be set using docker login command https://docs.docker.com/engine/reference/commandline/login/ or you can manually set the credentials in ~/.docker/config.json file.
Now you can build the image, it should pull the base image from registry.

How to launch a Docker container that i've got from another person?

I am a Docker-newbie and I've got a project from another developer including a Dockerfile. This shall give me the Virtual Machine to continue work with the (nodeJS-) project inside this project folder.
Docker is already installed on my machine.
How can I launch this container now?
I've read about a command
sudo docker run -name my_first_instance
but i can't find any container name in the Dockerfile.
The dockerfile will create an image for you that you can launch containers from. this being said , Follow this:
Create a folder.
Copy dockerfile in the folder
cd into the folder execute the following command:
docker build -t <your desired image name> .
This will create an image using directives in the dockerfile in the current folder.
Now launch a container from the image.
docker run -d --name <your container name> <imagename from previous step> <optional startup commands>
Useful docker commands:
You can expose ports in the previous command using -p switch.
You can list Images via docker images
You can list running containers via docker ps
you can list running + exited containers via docker ps -a
have a look at
https://hub.docker.com/_/node/
it is the official repository for NodeJS docker images
If you want some docker images based on NodeJS, you will need to pull them docker pull my_node_image
Then you can launch one with such a command
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:4 node your-daemon-or-script.js
The Dockerfile is just the recipe to build a docker image, for Nginx, Mysql, MongoDb, Redis, Wordpress, Spotify, atop, htop...
If docker images shows nothing, it means you have not yet pulled any docker image.

Resources