Environment to do the basic
yum install docker -y
service docker start
docker pull public.ecr.aws/amazonlinux/amazonlinux:latest
#after you will see in the image list doing
docker images
#run without login
docker run public.ecr.aws/amazonlinux/amazonlinux
#list running docker
docker ps -a
# docker run with login inside for debug
docker run -it public.ecr.aws/amazonlinux/amazonlinux /bin/bash
the pbulc repo is https://gallery.ecr.aws/amazonlinux/amazonlinux
SUMMARY
install and verify the installation
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
ecs-cli --version
configure
ecs-cli configure --region us-west-2 --cluster myClusterName
Repositories
it is a new features added in aws , you can create a new repos for each version of an image.
the guide is here http://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html
- create a new repository on Amazon ECS => Repositories => Create repository , you will receive back some useful commands. I created a repos called nginx
- first step you need to obtain a token to use the service. It is necessary run this command from a machine where you have the rights admin or the specific rights
aws ecr get-login --region eu-west-1
docker login -u AWS -p eyJwYXlsb2FkIjoiQXoyWmV
.......................................................................
IiwidmVyc2lvbiI6IjEiLCJ0eXBlIjoiREFUQV9LRVkifQ== -e none https://myaccountid.dkr.ecr.us-east-2.amazonaws.com
## COPY THIS DOCKER LOGIN COMMAND IN YOUR SHELL AND RUN IT SO YOU WILL HAVE ACCESS FOR THE OTHERS ACTIONS
- in my case i have created this repos in Ireland, copy the long token you can use for 12 hours in any machine where you have the image to import
- login in the machine where you have the images to import and run the command just copied. You should see as result something like that
WARNING: login credentials saved in ~/.docker/config.json
- run the command docker images and copy the image tag of the image that you want to upload in my case was
IMAGE ID
59fc1d5b6278
- tag the image , you need to use the image id just copied the repository name and a new tag latest or specific , you can find this command in the view commands inside the repos
docker tag 59fc1d5b6278 0123456789012.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
- push the repos you need to use the exact command just used for tag but using push instead of tag and without the image id
docker push 0123456789012.dkr.ecr.eu-west-1.amazonaws.com/nginx:latest
- after the upload you can see the image in your repos identified from the tag chosen in this example was latest
Windows
to have the command line to run the aws ecr you need to download the msi and install from here http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html
to authenticate you can run the command redirect the output in a file .ps1 and after run it again
aws ecr get-login --region eu-west-1 > login.ps1
run a container and login inside from windows
PS C:\Users\Administrator> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
amazon/amazon-ecs-credential-proxy latest 937616f0357b About an hour ago 10.2 GB
microsoft/windowsservercore latest 015cd665fbdd 2 weeks ago 10.2 GB
0123456789.dkr.ecr.us-east-2.amazonaws.com/test-cades-instance latest 195662cbe82d 3 weeks ago 10.4 GB
PS C:\Users\Administrator>
docker run -ti 0123456789.dkr.ecr.us-east-2.amazonaws.com/test-cades-instance powershell
LINUX ACADEMY COURSE
from linux academy Course: Using the EC2 Container Service
NOTE if you want install docker in a linux ami follow this guide http://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html
Containers: Docker Basics
download the latest ubuntu from docker hub https://hub.docker.com/_/ubuntu/
docker pull ubuntu
show the image just downloaded
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 42118e3df429 2 days ago 124.8 MB
run in interactive mode -i and in the terminal -t using the image and start a shell
docker run -it ubuntu:latest /bin/bash
when you exit this container will be stopped
with -a option show also the stopped container
docker ps -a
run the container with docker run
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 42118e3df429 2 days ago 124.8 MB
docker run 42118e3df429
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3100e8b28e35 42118e3df429 "/bin/bash" 1 seconds ago Exited (0) 1 seconds ago nostalgic_chandrasekhar
the container immediately exit after the run
save the container
- run the container login with bash
- modify it installing something, I installed lynx
- exit from the container
- run the docker ps -a and read the container id
- commit the container id with a new name
- check the list to see the new image
- run the new images
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
685f0e1d4085 ubuntu:latest "/bin/bash" 2 minutes ago Exited (0) 2 seconds ago furious_hamilton
docker commit 685f0e1d4085 mycontainer:lynx
sha256:b11f3440825814bbf043ffcf442835ea55023fad8c3c5efa0f71567d8c4d75bc
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycontainer lynx b11f34408258 6 seconds ago 173.7 MB
docker run -it mycontainer:lynx /bin/bash
Creating a custom container
Register to docker hub choose and username, in this example the username is latest123 but yours it will be different replace all the commands with the righ username
git clone https://github.com/awslabs/ecs-demo-php-simple-app
inside the directory you can find the docker file the most important lines are
# this container start from an ubuntu base
FROM ubuntu:12.04
...................
# expose the port 80 to the outisde
EXPOSE 80
# run the apache2 service like a daemon in foreground
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
we can build this container with the commmand
docker build -t latest123/amazon-ecs-sample .
after the build we can see it with the command
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
latest123/amazon-ecs-sample latest bf54adb8c1bd About a minute ago 228.6 MB
ubuntu 12.04 a11493a01736 9 days ago 103.6 MB
run the container and check if it is running
docker run -dp 80:80 latest123/amazon-ecs-sample:latest
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f6b6a7d89dab latest123/amazon-ecs-sample:latest "/usr/sbin/apache2 -D" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp focused_mayer
connect with the browser
lynx http://localhost
now we can stop and remove the container
docker stop focused_mayer
focused_mayer
docker rm focused_mayer
focused_mayer
login to the hub.docker.com
docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: pippopeppe83
Password:
Login Succeeded
after this login you can use the command docker info and you will have the a file in ~/.docker/config.json
docker push latest123/amazon-ecs-sample:latest