How do I deploy the Oracle Database Docker image on AWS EC2?
In this guide, we will deploy the Oracle Database Docker image on an AWS EC2 instance using Pulumi with TypeScript. We will create an EC2 instance, install Docker on it, and then run the Oracle Database Docker container.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create a new security group for the EC2 instance
const securityGroup = new aws.ec2.SecurityGroup("web-secgrp", {
description: "Allow SSH and HTTP access",
ingress: [
{ protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] }, // SSH
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }, // HTTP
],
});
// Create a new EC2 instance
const server = new aws.ec2.Instance("web-server", {
instanceType: "t2.micro",
vpcSecurityGroupIds: [securityGroup.id],
ami: aws.ec2.getAmi({
filters: [
{ name: "name", values: ["amzn2-ami-hvm-*-x86_64-gp2"] },
],
mostRecent: true,
owners: ["137112412989"], // Amazon
}).then(ami => ami.id),
userData: `#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo docker run -d -p 1521:1521 --name oracle-db store/oracle/database-enterprise:12.2.0.1-slim
`,
tags: {
Name: "web-server",
},
});
// Export the public IP of the instance
export const publicIp = server.publicIp;
export const publicHostName = server.publicDns;
Key Points
- Security Group: Configures the security group to allow SSH and HTTP access.
- EC2 Instance: Launches an EC2 instance with Amazon Linux 2 AMI and installs Docker.
- Docker Container: Runs the Oracle Database Docker container on the EC2 instance.
- Exports: Provides the public IP and DNS of the EC2 instance for access.
Summary
We have successfully deployed the Oracle Database Docker image on an AWS EC2 instance using Pulumi with TypeScript. The setup includes creating a security group, launching an EC2 instance, installing Docker, and running the Oracle Database container. This allows us to have an Oracle Database running in a Docker container on AWS.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.