Run docker image in my virtual machine with Terraform (Google Cloud Platform)

Ensure Docker installation: Add the following to startup-script.sh:

sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl start docker
docker pull myusername/myProject:master
docker run -d –name myProjectContainer myusername/myProject:master
Check logs: After the VM is running, view logs:

Startup logs: sudo journalctl -u google-startup-scripts.service
Docker logs: sudo docker logs myProjectContainer
Permissions: Ensure the script has execute permissions and the VM can access Docker registries.

Manual test: SSH into the VM and manually run the commands in the script to debug further

Read more here: Source link