Demo
Contributors: Alanna Zhou, Shungo Najima, Joshua Dirga
Last updated
Was this helpful?
Contributors: Alanna Zhou, Shungo Najima, Joshua Dirga
Last updated
Was this helpful?
Watch Demo Video
Uploaded on the AppDev YouTube channel!
Prepare your project. Make sure it is ready to be containerized
You may use this Dockerfile template here.
Configure your billing, for students enrolled in our course, navigate to and Start Free Trial or Redeem Credit.
Create your VPC Network
Name: name it anything you want!
Description: anything you want (optional)
Enable automatic subnet creation
Under Firewall Rules: enable Allow SSH
Create your VM
Machine Configuration (First tab on the left)
Name: name it anything you want!
Region: anyone should be fine, but closest to Ithaca is Northern Virginia.
Machine type: any, but to save costs we use e2-small
OS and storage (Second tab on the left)
Click "Change" and change the operating system to Ubuntu
Networking (Fourth tab on the left)
Under firewall, check "Allow HTTP traffic"
Under network interface, set the network to the VPC you created just now
Click "Create" to create you VM!
Build your Docker image locally and push to Dockerhub
docker build --platform=linux/amd64 -t joshuadirga/demo-5:v1.0.0 .
Make sure to set the platform flag to be linux/amd64
because our VM is using Ubuntu, a Linux based OS. Remember that the format for the Docker image is accountname/reponame:tagname
Run docker push joshuadirga/demo-5:v1.0.0 .
to push to Dockerhub
Check that your image is on .
SSH into your VM by clicking the "SSH" button under the "Connect" column
Follow steps 1 on the and the to install Docker and Docker Compose.
Pull your Docker image from Dockerhub using
sudo docker pull joshuadirga/demo-5:v1.0.0
Check that it successfully pulled by listing the images on your VM using
sudo docker images
Create a docker-compose.yml file using vim. vim docker-compose.yml
This will create a new docker-compose.yml file if it has not been created already.
Some useful VIM commands:
- press "i" on the keyboard to enter insertion mode (you can only edit in insertion mode)
- press "esc" to escape insertion mode
- once escaped from insertion mode type :w
to save file or :q
to exit VIM. Use :wq
to save and exit at the same time.
Make sure the image name is the same one you pushed to Dockerhub earlier. Remember that the port 80:5000
refers to container's port : app's port
. The container's port is the port you are running you Docker Container on inside the VM. The app's port is the port inside the container, where you are running your app (remember you app.py file uses the port 5000). Here is a template you may use for the docker-compose.yml!
Check that you docker-compose.yml exists by running cat docker-compose.yml
Run you app using sudo docker-compose up -d
to run in detached mode
Check that its running using sudo docker ps
to list all the running containers. Copy your container's id, and then use the command
sudo docker logs YOURCONTAINERID
To view the logs from your container. The logs should be similar to what you see when you run your app locally!
On GCP (Google Cloud Platform), click on the External IP for your VM to access the backend on your browser. Copy the URL over to postman to test, and CONGRATULATIONS YOU'VE MADE YOUR FIRST DEPLOYMENT!!
Run sudo docker-compose down
to kill your container. The next time you run, just run sudo docker-compose up -d
again because your images are still in your VM! If you made a change to your backend code and want to redeploy, here are the steps:
Build using docker build --platform=linux/amd64 -t joshuadirga/demo-5:v1.0.0 .
(Do this locally on your laptop's command line)
Push using docker push joshuadirga/demo-5:v1.0.0 .
(Do this locally on your laptop's command line)
Pull from Dockerhub using sudo docker pull joshuadirga/demo-5:v1.0.0
(Do this in your server)
Use sudo docker-compose up -d
to run!
Additional Tips:
You only need to change your docker-compose.yml if you are changing any of the configurations in running your container
A lot fo the problems encountered in this deployment setup is port issues, so remember to use port 80:5000
or something like 8080:5000
in your docker-compose.yml file.