Before You Begin
This 10-minute tutorial shows you how to deploy a Python application to Oracle Application Container Cloud Service.
Background
Oracle Application Container Cloud Service lets you deploy Java SE, Java EE, Node.js, PHP, Ruby, Go, .Net Core, and Python applications to the Oracle Cloud.
What Do You Need?
An Oracle Cloud account with access to Oracle Application Container Cloud Service
Create a Python Application
- Create the
python-app
project directory in your local system. - In the
python-app
directory, create theapp.py
file and add the following content:#!/usr/bin/python import os from http.server import BaseHTTPRequestHandler, HTTPServer PORT_NUMBER = int(os.environ.get('PORT', 8084)) # HTTPRequestHandler class class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): # GET def do_HEAD(self): # Send response status code self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() return # GET def do_GET(self): # Send response status code self.send_response(200) # Send headers self.send_header('Content-type','text/html') self.end_headers() # Send message back to client message = "Hello world!" # Write content as utf-8 data self.wfile.write(bytes(message, "utf8")) return def run(): print('starting server...') # Server settings # Choose port 8080, for port 80, which is normally used for a http server, you need root access server_address = ('0.0.0.0', PORT_NUMBER) httpd = HTTPServer(server_address, testHTTPServer_RequestHandler) print('running server...') httpd.serve_forever() run()
Prepare the Application for Deployment
- In the
python-app
directory, create themanifest.json
file and add the following content:{ "runtime": { "majorVersion": "3.6.0" }, "command": "python app.py", "notes": "Simple REST Service" }
- Open a command-line (or Terminal in Linux), go to the
python-app
directory, and compress themanifest.json
file and theapp.py
file together in a.zip
file.zip python-app.zip app.py manifest.json
Deploy Your Application to Oracle Application Container Cloud Service
- Open the Oracle Application Container Cloud Service console.
- In the Applications list view, click Create Application and select Python.
- In the Application section, enter a name for your application and click Browse.
- On the File Upload dialog box, select the
python-app.zip
file you created in the previous section and click Open. - Keep the default values in the Instances and Memory fields and click Create.
- Wait until the application is created. The URL is enabled when the creation is completed.
- Click the URL of your application.
Description of the illustration python-app-response.png
Want to Learn More?
- Creating a Python Application Using Oracle MySQL Cloud Service on Oracle Application Container Cloud Service
- Connect a Python Application to Oracle Database Cloud Service