Let's create a simples REST API using Docker, Oracle Cloud Instance with Ubuntu OS and Autonomous Database.
- Elevate permissions of private key with
chmod 400 <key_name>.key
- Use SSH to enter on CLI of VM with
ssh -i <key_name>.key <username>@<public_ip>
- On root folder, create the image running:
docker build -t sampleapi -f docker/Dockerfile backend/sampleapi/
- Run container with
docker run -d -p 80:80 --name sampleapi sampleapi
- Firstly, download you code on VM to create the image locally. I will use git for clone this repo on Oracle VM typing
git clone https://github.com/peedroca/docker-oracle-cloud.git
- Go to cloned repo with
cd docker-oracle-cloud
, and than I will run the code above to generate and run my container. Maybe you need execute the command with sudo permission like:sudo docker build ...
- I can test the container execution just typing
curl http://localhost/WeatherForecast
- On cloud platform go to Instances > Primary VNIC > Subnet > Security Lists.
- Add an Ingress Rules with configuration:
{
"Stateless": false,
"Source Type": "CIDR",
"Source CIDR": "0.0.0.0/0",
"IP Protocol": "TCP",
"Source Port Range": "All",
"Destination Port Range": "80",
"Description": "Sample API"
}
- Test using the Public IP like
http://<public_ip>/WeatherForecast
.