Amazon linux 2 ami install docker

Docker basics for Amazon ECS

Docker is a technology that provides the tools for you to build, run, test, and deploy distributed applications that are based on Linux containers. Amazon ECS uses Docker images in task definitions to launch containers as part of tasks in your clusters.

AWS and Docker have collaborated to make a simplified developer experience that enables you to deploy and manage containers on Amazon ECS directly using Docker tools. You can now build and test your containers locally using Docker Desktop and Docker Compose, and then deploy them to Amazon ECS on Fargate. To get started with the Amazon ECS and Docker integration, download Docker Desktop and optionally sign up for a Docker ID. For more information, see Docker Desktop and Docker ID signup .

Docker provides a walkthrough on deploying containers on Amazon ECS. For more information, see Deploying Docker containers on Amazon ECS .

The documentation in this guide assumes that readers possess a basic understanding of what Docker is and how it works. For more information about Docker, see What is Docker? and the Docker overview .

Installing Docker

If you already have Docker installed, skip to Create a Docker image.

Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to build and share containerized applications and microservices. Docker Desktop includes Docker Engine, the Docker CLI client, Docker Compose, and other tools that are helpful when using Docker with Amazon ECS. For more information about how to install Docker Desktop on your preferred operating system, see Docker Desktop overview .

If you don’t need a local development environment and you prefer to use an Amazon EC2 instance to use Docker, we provide the following steps to launch an Amazon EC2 instance and install Docker Engine and the Docker CLI.

To install Docker on an Amazon EC2 instance

Launch an instance with the Amazon Linux 2 or Amazon Linux AMI. For more information, see Launching an instance in the Amazon EC2 User Guide for Linux Instances.

Connect to your instance. For more information, see Connect to your Linux instance in the Amazon EC2 User Guide for Linux Instances.

Update the installed packages and package cache on your instance.

Install the most recent Docker Engine package.

Start the Docker service.

Add the ec2-user to the docker group so you can execute Docker commands without using sudo .

Log out and log back in again to pick up the new docker group permissions. You can accomplish this by closing your current SSH terminal window and reconnecting to your instance in a new one. Your new SSH session will have the appropriate docker group permissions.

Verify that the ec2-user can run Docker commands without sudo .

In some cases, you may need to reboot your instance to provide permissions for the ec2-user to access the Docker daemon. Try rebooting your instance if you see the following error:

Create a Docker image

Amazon ECS task definitions use Docker images to launch containers on the container instances in your clusters. In this section, you create a Docker image of a simple web application, and test it on your local system or Amazon EC2 instance, and then push the image to a container registry (such as Amazon ECR or Docker Hub) so you can use it in an Amazon ECS task definition.

To create a Docker image of a simple web application

Create a file called Dockerfile . A Dockerfile is a manifest that describes the base image to use for your Docker image and what you want installed and running on it. For more information about Dockerfiles, go to the Dockerfile Reference .

Edit the Dockerfile you just created and add the following content.

This Dockerfile uses the Ubuntu 18.04 image. The RUN instructions update the package caches, install some software packages for the web server, and then write the «Hello World!» content to the web server’s document root. The EXPOSE instruction exposes port 80 on the container, and the CMD instruction starts the web server.

Build the Docker image from your Dockerfile.

Some versions of Docker may require the full path to your Dockerfile in the following command, instead of the relative path shown below.

Run docker images to verify that the image was created correctly.

Run the newly built image. The -p 80:80 option maps the exposed port 80 on the container to port 80 on the host system. For more information about docker run, go to the Docker run reference .

Output from the Apache web server is displayed in the terminal window. You can ignore the » Could not reliably determine the server’s fully qualified domain name » message.

Читайте также:  Codec windows media player virtualdub

Open a browser and point to the server that is running Docker and hosting your container.

If you are using an EC2 instance, this is the Public DNS value for the server, which is the same address you use to connect to the instance with SSH. Make sure that the security group for your instance allows inbound traffic on port 80.

If you are running Docker locally, point your browser to http://localhost/ .

If you are using docker-machine on a Windows or Mac computer, find the IP address of the VirtualBox VM that is hosting Docker with the docker-machine ip command, substituting machine-name with the name of the docker machine you are using.

You should see a web page with your «Hello World!» statement.

Stop the Docker container by typing Ctrl + c.

Push your image to Amazon Elastic Container Registry

Amazon ECR is a managed AWS Docker registry service. You can use the Docker CLI to push, pull, and manage images in your Amazon ECR repositories. For Amazon ECR product details, featured customer case studies, and FAQs, see the Amazon Elastic Container Registry product detail pages .

This section requires the following:

You have the AWS CLI installed and configured. If you do not have the AWS CLI installed on your system, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.

Your user has the required IAM permissions to access the Amazon ECR service. For more information, see Amazon ECR managed policies.

To tag your image and push it to Amazon ECR

Create an Amazon ECR repository to store your hello-world image. Note the repositoryUri in the output.

Tag the hello-world image with the repositoryUri value from the previous step.

Run the aws ecr get-login-password command. Specify the registry URI you want to authenticate to. For more information, see Registry Authentication in the Amazon Elastic Container Registry User Guide.

If you receive an error, install or upgrade to the latest version of the AWS CLI. For more information, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.

Push the image to Amazon ECR with the repositoryUri value from the earlier step.

Clean up

When you are done experimenting with your Amazon ECR image, you can delete the repository so you are not charged for image storage.

Источник

Migrating to the Docker Amazon Linux 2 Platform

Amazon Linux 2 platform versions are fundamentally different than Amazon Linux AMI platform versions (preceding Amazon Linux 2). These different platform generations are incompatible in several ways. If you are migrating to an Amazon Linux 2 platform version, be sure to read the information in Migrating your Elastic Beanstalk Linux application to Amazon Linux 2.

You can migrate your applications running on the Multi-container Docker platform on Amazon Linux AMI to the Amazon Linux 2 Docker platform. The Multi-container Docker platform on Amazon Linux AMI requires that you specify prebuilt application images to run as containers. After migrating, you will no longer have this limitation, because the Amazon Linux 2 Docker platform also allows Elastic Beanstalk to build your container images during deployment.

Your applications will continue to run in multi-container environments with the added benefits from the Docker Compose tool. To learn more about Docker Compose and how to install it, see the Docker sites Overview of Docker Compose and Install Docker Compose .

The docker-compose.yml file

The Docker Compose tool uses the docker-compose.yml file for configuration of your application services. This file replaces your Dockerrun.aws.json v2 file in your application project directory and application source bundle. You create the docker-compose.yml file manually, and will find it helpful to reference your Dockerrun.aws.json v2 file for most of the parameter values.

Below is an example of a docker-compose.yml file and the corresponding Dockerrun.aws.json v2 file for the same application. For more information on the docker-compose.yml file, see Compose file reference . For more information on the Dockerrun.aws.json v2 file, see Dockerrun.aws.json v2.

Additional Migration Considerations

The Docker Amazon Linux 2 platform and Multi-container Docker Amazon Linux AMI platform implement environment properties differently. These two platforms also have different log directories that Elastic Beanstalk creates for each of their containers. After you migrate from the Amazon Linux AMI Multi-container Docker platform, you will need to be aware of these different implementations for your new Amazon Linux 2 Docker platform environment.

docker-compose.yml Dockerrun.aws.json v2

In order for your containers to access environment properties you must add a reference to the .env file in the docker-compose.yml file. Elastic Beanstalk generates the .env file, listing each of the properties as environment variables. For more information see Referencing environment variables in containers.

Elastic Beanstalk can directly pass environment properties to the container. Your code running in the container can access these properties as environment variables without any additional configuration.

For each container Elastic Beanstalk creates a log directory called /var/log/eb-docker/containers/ (or $ < EB_LOG_BASE_DIR>/ ). For more information see Docker container customized logging (Docker Compose).

For each container, Elastic Beanstalk creates a log directory called /var/log/containers/ . For more information see mountPoints field in Container definition format.

Migration Steps

To migrate to the Amazon Linux 2 Docker platform

Create the docker-compose.yml file for your application, based on its existing Dockerrun.aws.json v2 file. For more information see the above section The docker-compose.yml file.

In your application project folder’s root directory, replace the Dockerrun.aws.json v2 file with the docker-compose.yml you just created.

Your directory structure should be as follows.

Use the eb init command to configure your local directory for deployment to Elastic Beanstalk.

Use the eb create command to create an environment and deploy your Docker image.

If your app is a web application, after your environment launches, use the eb open command to view it in a web browser.

You can display the status of your newly created environment using the eb status command.

Источник

Using Amazon ECR with the AWS CLI

The following steps walk you through the steps needed to push a container image to a private Amazon ECR repository for the first time using the Docker CLI and the AWS CLI.

For more information on the other tools available for managing your AWS resources, including the different AWS SDKs, IDE toolkits, and the Windows PowerShell command line tools, see http://aws.amazon.com/tools/ .

Prerequisites

Before you begin, be sure that you have completed the steps in Setting up with Amazon ECR.

If you do not already have the latest AWS CLI and Docker installed and ready to use, use the following steps to install both of these tools.

Install the AWS CLI

You can use the AWS command line tools to issue commands at your system’s command line to perform Amazon ECR and other AWS tasks. This can be faster and more convenient than using the console. The command line tools are also useful for building scripts that perform AWS tasks.

To use the AWS CLI with Amazon ECR, install the latest AWS CLI version (Amazon ECR functionality is available in the AWS CLI starting with version 1.9.15). You can check your AWS CLI version with the aws —version command. For information about installing the AWS CLI or upgrading it to the latest version, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.

Install Docker

Docker is available on many different operating systems, including most modern Linux distributions, like Ubuntu, and even macOS and Windows. For more information about how to install Docker on your particular operating system, go to the Docker installation guide .

You don’t need a local development system to use Docker. If you are using Amazon EC2 already, you can launch an Amazon Linux 2 instance and install Docker to get started.

If you already have Docker installed, skip to Step 1: Create a Docker image.

To install Docker on an Amazon EC2 instance

Launch an instance with the Amazon Linux 2 AMI. For more information, see Launching an Instance in the Amazon EC2 User Guide for Linux Instances.

Connect to your instance. For more information, see Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances.

Update the installed packages and package cache on your instance.

Install the most recent Docker Community Edition package.

Start the Docker service.

Add the ec2-user to the docker group so you can execute Docker commands without using sudo .

Log out and log back in again to pick up the new docker group permissions. You can accomplish this by closing your current SSH terminal window and reconnecting to your instance in a new one. Your new SSH session will have the appropriate docker group permissions.

Verify that the ec2-user can run Docker commands without sudo .

In some cases, you may need to reboot your instance to provide permissions for the ec2-user to access the Docker daemon. Try rebooting your instance if you see the following error:

Step 1: Create a Docker image

In this section, you create a Docker image of a simple web application, and test it on your local system or EC2 instance, and then push the image to a container registry (such as Amazon ECR or Docker Hub) so you can use it in an ECS task definition.

To create a Docker image of a simple web application

Create a file called Dockerfile . A Dockerfile is a manifest that describes the base image to use for your Docker image and what you want installed and running on it. For more information about Dockerfiles, go to the Dockerfile Reference .

Edit the Dockerfile you just created and add the following content.

This Dockerfile uses the Ubuntu 18.04 image. The RUN instructions update the package caches, install some software packages for the web server, and then write the «Hello World!» content to the web server’s document root. The EXPOSE instruction exposes port 80 on the container, and the CMD instruction starts the web server.

Build the Docker image from your Dockerfile.

Some versions of Docker may require the full path to your Dockerfile in the following command, instead of the relative path shown below.

Run docker images to verify that the image was created correctly.

Run the newly built image. The -p 80:80 option maps the exposed port 80 on the container to port 80 on the host system. For more information about docker run, go to the Docker run reference .

Output from the Apache web server is displayed in the terminal window. You can ignore the » Could not reliably determine the server’s fully qualified domain name » message.

Open a browser and point to the server that is running Docker and hosting your container.

If you are using an EC2 instance, this is the Public DNS value for the server, which is the same address you use to connect to the instance with SSH. Make sure that the security group for your instance allows inbound traffic on port 80.

If you are running Docker locally, point your browser to http://localhost/ .

If you are using docker-machine on a Windows or macOS computer, find the IP address of the VirtualBox VM that is hosting Docker with the docker-machine ip command, substituting machine-name with the name of the docker machine you are using.

You should see a web page with your «Hello World!» statement.

Stop the Docker container by typing Ctrl + c.

Step 2: Authenticate to your default registry

After you have installed and configured the AWS CLI, authenticate the Docker CLI to your default registry. That way, the docker command can push and pull images with Amazon ECR. The AWS CLI provides a get-login-password command to simplify the authentication process.

The get-login-password is the preferred method for authenticating to an Amazon ECR private registry when using the AWS CLI. Ensure that you have configured your AWS CLI to interact with AWS. For more information, see AWS CLI configuration basics in the AWS Command Line Interface User Guide.

When passing the Amazon ECR authorization token to the docker login command, use the value AWS for the username and specify the Amazon ECR registry URI you want to authenticate to. If authenticating to multiple registries, you must repeat the command for each registry.

If you receive an error, install or upgrade to the latest version of the AWS CLI. For more information, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.

Get-ECRLoginCommand (AWS Tools for Windows PowerShell)

Step 3: Create a repository

Now that you have an image to push to Amazon ECR, you must create a repository to hold it. In this example, you create a repository called hello-world to which you later push the hello-world:latest image. To create a repository, run the following command:

Step 4: Push an image to Amazon ECR

Now you can push your image to the Amazon ECR repository you created in the previous section. You use the docker CLI to push images, but there are a few prerequisites that must be satisfied for this to work properly:

The minimum version of docker is installed: 1.7

The Amazon ECR authorization token has been configured with docker login.

The Amazon ECR repository exists and the user has access to push to the repository.

After those prerequisites are met, you can push your image to your newly created repository in the default registry for your account.

To tag and push an image to Amazon ECR

List the images you have stored locally to identify the image to tag and push.

Tag the image to push to your repository.

Step 5: Pull an image from Amazon ECR

After your image has been pushed to your Amazon ECR repository, you can pull it from other locations. Use the docker CLI to pull images, but there are a few prerequisites that must be satisfied for this to work properly:

The minimum version of docker is installed: 1.7

The Amazon ECR authorization token has been configured with docker login.

The Amazon ECR repository exists and the user has access to pull from the repository.

After those prerequisites are met, you can pull your image. To pull your example image from Amazon ECR, run the following command:

Step 6: Delete an image

If you decide that you no longer need or want an image in one of your repositories, you can delete it with the batch-delete-image command. To delete an image, you must specify the repository that it is in and either a imageTag or imageDigest value for the image. The example below deletes an image in the hello-world repository with the image tag latest .

Step 7: Delete a repository

If you decide that you no longer need or want an entire repository of images, you can delete the repository. By default, you cannot delete a repository that contains images; however, the —force flag allows this. To delete a repository that contains images (and all the images within it), run the following command.

Источник

Читайте также:  Система управления конфигурациями linux
Оцените статью
Area Docker platform on Amazon Linux 2 with Docker Compose Multi-container Docker platform on Amazon Linux AMI