I recently wrote an article series on how to use Amazon Web Services’ EC2 Container Service to deploy a simple application container. Although deploying a sample app is a good place to start, it’s not something you will be able to do in the real-world.
If you plan to use containers in production, you will need to learn how to push a Docker Image to AWS. This article will show you how to do it.
Before I begin, let me mention a few prerequisites. First, I assume that you have a container image you wish to push to AWS. Second, I assume that you have Docker and AWS Command Line Environments (CLI) installed in your local environment.
Let’s now get started.
First, you should know that container images are stored within a container repository in the AWS cloud. AWS allows you to create a container repository using the GUI, but you will need to use the command line to add images to that repository.
Log in to AWS console and select the EC2 Container Service option. This option can be found in the Compute section. This will open AWS’ Clusters dashboard. You will see that the dashboard has a Repositories tab. This tab is located on the left-hand side of the screen. Click on Repositories.
[Click on the image to see a larger version.] Figure 1: Click the Repositories link. You will now be taken to the Repositories screen. Figure 2 shows this. This screen is quite simple, as you can see. It lists all existing repositories, and has buttons that allow you to create or remove repositories.
[Click on the image to see a larger view.] Figure 2: This screen shows the Repositories screen. Click on the button to create your repository. After clicking the button, you will be taken on a screen similar to Figure 3. Simply enter the name of the repository you wish to create, and then click the Next Step button. The repository will be created once you have done this.
[Click on the image to see a larger view.] Figure 3: Type a name for your repository and click the Next Step button. Before I proceed, I want to highlight a few things about this screen. AWS lists the repository URI. Before you click Next Step, make sure you write down the URI after you have typed the repository name.
Another thing to note is that the screen shows that the repository owner (you), has default access to the repository. However, you will need access granted to anyone else who requires it.
The container repository has been created at this point. Although it is not easy to authenticate your Docker client into the registry, AWS provides some guidance on the next screen. The first step is to find the command used to log in. AWS provides a command that can be used to retrieve the log in command. It looks something like this:
aws get-login ecr –no-include email –region US-West-2Next, log in. If you are using a Linux system, you will need the command returned by the previous command. AWS also offers a PowerShell command for Windows systems. AWS provides an example PowerShell command:
Invoke-Expression –Command (aws-ecr get–login –no–include-email -region us-west-2The next stage in the process is to build the Docker Image, as described in the instructions. AWS provides the following command:
Docker build -t Sample. You will notice that this command (and both the next two) uses the word Sample. Sample is my repository name, so your commands will be slightly different.
Now you will need to
