Preconfigured Docker containers (Amazon Linux AMI)
Note
On July 18,2022, Elastic Beanstalk set the status of all platform branches based on Amazon Linux AMI (AL1) to retired. For more information about migrating to a current and fully supported Amazon Linux 2023 platform branch, see Migrating your Elastic Beanstalk Linux application to Amazon Linux 2023 or Amazon Linux 2.
The Preconfigured Docker GlassFish platform branch that runs on the Amazon Linux AMI (AL1) is no longer supported. To migrate your GlassFish application to a supported Amazon Linux 2023 platform, deploy GlassFish and your application code to an Amazon Linux 2023 Docker image. For more information, see the following topic, Deploying a GlassFish application to the Docker platform: a migration path to Amazon Linux 2023.
This section shows you how to develop an example application locally and then deploy your application to Elastic Beanstalk with a preconfigured Docker container.
Set up your local development environment
For this walk-through we use a GlassFish example application.
To set up your environment
-
Create a new folder for the example application.
~$
mkdir eb-preconf-example
~$cd eb-preconf-example
-
Download the example application code into the new folder.
~$
wget https://docs.amazonaws.cn/elasticbeanstalk/latest/dg/samples/docker-glassfish-v1_cn.zip
~$unzip docker-glassfish-v1_cn.zip
~$rm docker-glassfish-v1_cn.zip
Develop and test locally
To develop an example GlassFish application
-
Add a
Dockerfile
to your application’s root folder. In the file, specify the Amazon Elastic Beanstalk Docker base image to be used to run your local preconfigured Docker container. You'll later deploy your application to an Elastic Beanstalk Preconfigured Docker GlassFish platform version. Choose the Docker base image that this platform version uses. To find out the current Docker image of the platform version, see the Preconfigured Docker section of the Amazon Elastic Beanstalk Supported Platforms page in the Amazon Elastic Beanstalk Platforms guide.Example ~/Eb-preconf-example/Dockerfile
# For Glassfish 5.0 Java 8 FROM amazon/aws-eb-glassfish:5.0-al-onbuild-2.11.1
For more information about using a
Dockerfile
, see Docker configuration. -
Build the Docker image.
~/eb-preconf-example$
docker build -t my-app-image .
-
Run the Docker container from the image.
Note
You must include the
-p
flag to map port 8080 on the container to the localhost port 3000. Elastic Beanstalk Docker containers always expose the application on port 8080 on the container. The-it
flags run the image as an interactive process. The--rm
flag cleans up the container file system when the container exits. You can optionally include the-d
flag to run the image as a daemon.$
docker run -it --rm -p 3000:8080 my-app-image
-
To view the example application, type the following URL into your web browser.
http://localhost:3000
Deploy to Elastic Beanstalk
After testing your application, you are ready to deploy it to Elastic Beanstalk.
To deploy your application to Elastic Beanstalk
-
In your application's root folder, rename the
Dockerfile
toDockerfile.local
. This step is required for Elastic Beanstalk to use theDockerfile
that contains the correct instructions for Elastic Beanstalk to build a customized Docker image on each Amazon EC2 instance in your Elastic Beanstalk environment.Note
You do not need to perform this step if your
Dockerfile
includes instructions that modify the platform version's base Docker image. You do not need to use aDockerfile
at all if yourDockerfile
includes only aFROM
line to specify the base image from which to build the container. In that situation, theDockerfile
is redundant. -
Create an application source bundle.
~/eb-preconf-example$
zip myapp.zip -r *
-
Open the Elastic Beanstalk console with this preconfigured link: console.amazonaws.cn/elasticbeanstalk/home#/newApplication?applicationName=tutorials&environmentType=LoadBalanced
-
For Platform, under Preconfigured – Docker, choose Glassfish.
-
For Application code, choose Upload your code, and then choose Upload.
-
Choose Local file, choose Browse, and then open the application source bundle you just created.
-
Choose Upload.
-
Choose Review and launch.
-
Review the available settings, and then choose Create app.
-
When the environment is created, you can view the deployed application. Choose the environment URL that is displayed at the top of the console dashboard.