Google cloud's Compute Engine is virtual machines.
each virtual machine is called instance.
each instance is started or stopped manually.
When instance is started and in running state, the billing is counted until the instance is stopped.
-> if you want all controls of a computer, use this.
-> can support linux, ubuntu or windows os.
-> remember to stop it when you donot use it.
-> if you want a solution that automatically start/stop instance, use Google Cloud Run
.
( https://cloud.google.com/compute/docs/create-linux-vm-instance https://cloud.google.com/compute/all-pricing https://cloud.google.com/compute/docs/instances )
-
go to 'console/Compute Engine/VM instances' and click 'Create instance'
-
select region. eg: us-central1 (lowa) note: the
asia-southeast1 (singapore)
is not supported region to gain the benefits of Free Tier. Use it will cost you more. (https://cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits) -
select machine: E2, e2-medium
-
select Boot Disk: Ubuntu, Ubuntu 20.04 LTS
-
select Firewall: allow http and allow https
-
check the price on the right panel: about $25/month => $0.03/hour
-
click 'Create'
(https://cloud.google.com/compute/docs/create-linux-vm-instance)
go to 'console/Compute Engine/VM instances'. click the 'three dots button' on the right of each instance and select 'start/resume' or 'stop'. -> remember to stop instance when not using it.
go to 'console/Compute Engine/VM instances'. click the 'SSH button' on the right of each instance. browser will open another windows that acts as an terminal to execute commands.
internally, googles does the followings: https://cloud.google.com/compute/docs/instances/ssh#metadata-managed_ssh_connections
you can create and store keys anywhere you like.
https://cloud.google.com/compute/docs/connect/create-ssh-keys#windows-10-or-later
(the key generated by ssh-keygen may not in the supported format of putty or winscp. if then those programs want to convert key to their supported format, just accept it. they will convert and put new keys besides the old keys. also remember the passphrase to use private key later or just dont use passphrase.)
this method doesn't require client to provide password. (recommended because of simplicity) It registers the username with client's public key. https://cloud.google.com/compute/docs/connect/add-ssh-keys#add_ssh_keys_to_instance_metadata
(view os login method here: https://cloud.google.com/compute/docs/instances/ssh#os_login-managed_ssh_connections )
https://cloud.google.com/compute/docs/connect/ssh-using-third-party-tools#putty
- select new session
- enter hostname (server ip), port: 22
- enter username, no need of password.
- click 'Advanced', click tab 'SSH/Authentication'.
- select the private key. (if asked for converting to, just accept it)
- select 'OK' to save authentication method.
- select 'Login'.
the simplest solution is upload the '.env' file to instance (using WinScp). then: export ABC=$(cat .env)
then use in docker container: sudo -E docker run -dp 3000:3000 --env ABC app1
your program should receive entire file content then parse it.
( another solution is using custom metadata and run custom script: https://cloud.google.com/compute/docs/metadata/overview#custom )