Elastic Beanstalk has a platform version running a Docker container that is preconfigured with the Java EE Glassfish application server software stack. You can use the preconfigured Docker container to develop and test your application locally and then deploy the application in an Elastic Beanstalk environment that is identical to your local environment.
Elastic Beanstalk also supports platform versions with preconfigured Docker containers for Go and Python. These platform versions are scheduled for retirement.
The following section provides a detailed procedure for deploying an application to Elastic Beanstalk using a preconfigured Docker container.
For details about currently supported preconfigured Docker platform versions, see Preconfigured Docker in the AWS Elastic Beanstalk Platforms document.
This section shows you how to develop an example application locally and then deploy your application to Elastic Beanstalk with a preconfigured Docker container.
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.aws.amazon.com/elasticbeanstalk/latest/dg/samples/docker-glassfish-v1.zip ~$ unzip docker-glassfish-v1.zip ~$ rm docker-glassfish-v1.zip
To develop an example Glassfish application
Dockerfileto your application’s root folder. In the file, specify the AWS 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 AWS Elastic Beanstalk Supported Platforms page in the AWS Elastic Beanstalk Platforms guide.
# 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 Single Container 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
-pflag 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
-itflags run the image as an interactive process. The
--rmflag cleans up the container file system when the container exits. You can optionally include the
-dflag 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.
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.local. This step is required for Elastic Beanstalk to use the
Dockerfilethat 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
Dockerfileincludes instructions that modify the platform version's base Docker image. You do not need to use a
Dockerfileat all if your
Dockerfileincludes only a
FROMline to specify the base image from which to build the container. In that situation, the
Create an application source bundle.
~/eb-preconf-example$ zip myapp.zip -r *
Open the Elastic Beanstalk console with this preconfigured link: console.aws.amazon.com/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 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.