This demos shows how to build a Docker container serving as a webserver. The webserver hosts a static webpage. Afterwards, we will push the Docker container to AWS. Finally, the Docker container used to launch an Amazon ECS cluster. But we can used Amazon SQS and Amazon EC2 to create a pipline.
-
First, (install and) activate Docker.
-
Generate the
Dockerfile
.touch Dockerfile
Edit the file, e.g. with
nano Dockerfile
. An example can be found here. -
Build and tag the Docker container:
docker build -t hello-world .
-
Test your container on localhost:
docker run --rm -p 80:80 hello-world
-
Stop your running container:
docker ps
to retrieve the contaibner-IDdocker stop container-ID
-
Create a AWS ECR repository via the CLI:
aws ecr create-repository --repository-name hello-repository --region eu-central-1
Change
repository-name
andregion
accordingly. -
Copy
uri
to your clipboard. -
Tag the Docker container for your respository:
docker tag hello-world XXX.dkr.ecr.eu-west-1.amazonaws.com/hello-repository # XXX = your account-ID
Change the
uri
accordingly. -
Get temporary credentials for your repository via the CLI:
aws ecr get-login-password --profile myaws\ --region eu-central-1\ | docker login \ --username AWS \ --password-stdin XXX.dkr.ecr.eu-central-1.amazonaws.com # XXX = your account-ID
Copy the output to your clipboard.
-
Push the Docker container to your repository:
docker push XXX.dkr.ecr.eu-west-1.amazonaws.com/hello-repository # XXX = your account-ID
-
Go the ECS service. Click on
Get started
and chooseCostum container
. Set the port settings to 80. -
After ECS deployed your application, get the
DNS-Name
of the deployedELB
(e.g. EC2 console). Paste it in to your browser tab.