Skip to content

Latest commit

 

History

History
63 lines (57 loc) · 3.53 KB

DeployOnCloudRun1.md

File metadata and controls

63 lines (57 loc) · 3.53 KB

Deploying a project with Cloud Run

In this article, we will learn how to deploy a simple HTML project on the cloud run.

  • First, upload the project to the google cloud by clicking on the upload button in the drop down menu of the cloud shell. upload
  • Then, click on upload folder and select the project folder from your local machine.
    upload
  • Once uploaded, confirm the same by using the ls command in the cloud shell.
    upload-success ls
  • Now, we need to create a docker image of the project. For this, we need to create a Dockerfile in the project folder. The Dockerfile should contain the following code:
FROM ubuntu:latest

# Update and install Nginx
RUN apt-get update && \
    apt-get install -y nginx && \
    rm -rf /var/www/html/

# Copy Nginx configuration file
COPY . /var/www/html/

# Expose port 80
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
  • Now, to build the docker image, run the following commands in the cloud shell:
docker build -t movies_search:v1 .

In the above command, movies_search is the name of the project and v1 is the version of the project. The '.' at the end of the command is the path of the Dockerfile, which is the current directory. docker-build

  • Now, to check if the docker image is created, run the following command:
docker images

docker-images

  • Now, to run the docker image, run the following command:
docker run -p 8080:80 movies_search:v1

In the above command, -p is used to map the port 8080 of the local machine to the port 80 of the docker container. movies_search is the name of the project and v1 is the version of the project. The above command will run the docker image in the port 8080 of the google cloud shell. To access the project, go to the web preview option in the drop down menu of the cloud shell and click on the port 8080. docker-run

  • Now, the project is running in the cloud shell, but to make it available to the public, we need to deploy it on the cloud run. For this, first we should push the docker image to the google cloud container registry. For this, run the following commands:
docker tag movies_search:v1 gcr.io/PROJECT_ID/movies_search:v1
docker push gcr.io/PROJECT_ID/movies_search:v1

In the above commands, gcr.io/PROJECT_ID is the path of the google cloud container registry. PROJECT_ID is the id of the project. movies_search is the name of the project and v1 is the version of the project. docker-tag

  • Now, to deploy the project on the cloud run, search for cloud run in the search bar of the google cloud console and click on the cloud run option. Then, click on "Create Service" button. In the next page, select the image from the google cloud container registry, which we have pushed in the previous step. In the "Authentication" section, select "Allow unauthenticated invocations" as we want to make the project available to the public. Then, make the other necessary changes and click on the "Create" button. cloud-run cloud-run-2
  • Now, the project is deployed on the cloud run!🥳 cloud-run-success-1 cloud-run-demo
  • You can check out my deployed project here.
  • The above steps are the basic steps to deploy a project on the cloud run. For more information, you can refer to the official documentation.