Preconfigured Docker containers (Amazon Linux AMI) - Amazon Elastic Beanstalk
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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
  1. Create a new folder for the example application.

    ~$ mkdir eb-preconf-example ~$ cd eb-preconf-example
  2. 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
  1. 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.

  2. Build the Docker image.

    ~/eb-preconf-example$ docker build -t my-app-image .
  3. 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
  4. To view the example application, type the following URL into your web browser.

    http://localhost:3000
    
                The GlassFish example application showing in a web browser

Deploy to Elastic Beanstalk

After testing your application, you are ready to deploy it to Elastic Beanstalk.

To deploy your application to Elastic Beanstalk
  1. In your application's root folder, rename the Dockerfile to Dockerfile.local. This step is required for Elastic Beanstalk to use the Dockerfile 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 a Dockerfile at all if your Dockerfile includes only a FROM line to specify the base image from which to build the container. In that situation, the Dockerfile is redundant.

  2. Create an application source bundle.

    ~/eb-preconf-example$ zip myapp.zip -r *
  3. Open the Elastic Beanstalk console with this preconfigured link: console.amazonaws.cn/elasticbeanstalk/home#/newApplication?applicationName=tutorials&environmentType=LoadBalanced

  4. For Platform, under Preconfigured – Docker, choose Glassfish.

  5. For Application code, choose Upload your code, and then choose Upload.

  6. Choose Local file, choose Browse, and then open the application source bundle you just created.

  7. Choose Upload.

  8. Choose Review and launch.

  9. Review the available settings, and then choose Create app.

  10. 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.