Build Docker image with AWS CLI tools installed

Using Docker image with AWS CLI tools installed

docker@boot2docker:~$ docker pull sdevarapalli/aws-cli
Using default tag: latest
latest: Pulling from sdevarapalli/aws-cli

3d8673bd162a: Pull complete
da63d6cdd79e: Pull complete
13e98e81fd0b: Pull complete
6722a77327b6: Pull complete
6d930c14ca40: Pull complete
b3c4f1214f20: Pull complete
Digest: sha256:9e50b198a8909febe940b7fd702c7f92d9ff353e941140be06c7a9b9d38fd67a
Status: Downloaded newer image for sdevarapalli/aws-cli:latest
docker@boot2docker:~$
docker@boot2docker:~$
docker@boot2docker:~$
docker@boot2docker:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sdevarapalli/aws-cli latest ec15aa2e51a2 37 minutes ago 699.6 MB
docker@boot2docker:~$
docker@boot2docker:~$
docker@boot2docker:~$
docker@boot2docker:~$docker run -i -t -h aws-cli \
--env AWS_ACCESS_KEY_ID=REPLACE_WITH_ACCESS_KEY_ID \
--env AWS_SECRET_ACCESS_KEY=REPLACE_WITH_SECRET_ACCESS_KEY \
--env AWS_DEFAULT_REGION=us-east-1 \
sdevarapalli/aws-cli /bin/bash
[root@aws-cli /]# aws iam list-users
{
"Users": [
{
"UserName": "xyz",
"PasswordLastUsed": "1900-01-01T01:01:01Z",
"CreateDate": "1900-01-01T01:01:01Z",
"UserId": "1111111",
"Path": "/",
"Arn": "arn:aws:iam::111111:user/xyz"
}
]
}
[root@aws-cli /]#

Steps to build and publish image

Build Image

$ git clone https://github.com/sdevarapalli1/aws-cli.git
# cd aws-cli
$ docker build -t sdevarapalli/aws-cli:latest -t sdevarapalli/aws-cli:0.2 .
......
......
......
Successfully built ec15aa2e51a2
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sdevarapalli/aws-cli latest ec15aa2e51a2 2 minutes ago 699.6 MB

Log in and Publish Image to Docker Hub

docker@boot2docker:~$ 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 (sdevarapalli):
Password:
Login Succeeded


docker@boot2docker:~$ docker push sdevarapalli/aws-cli:latest
The push refers to a repository [docker.io/sdevarapalli/aws-cli]
6044067d6476: Pushed
4d04059a14fc: Pushed
2c54e224dec4: Pushed
f6ff5fe8484d: Pushed
e1ada7271bd0: Pushed
f59b7e59ceaa: Pushed
latest: digest: sha256:9e50b198a8909febe940b7fd702c7f92d9ff353e941140be06c7a9b9d38fd67a size: 1583
docker@boot2docker:~$
Advertisements

Boot2docker setup on Mac OS X

Boot2docker is officially deprecated. Use Docker for Mac if Mac OS X version is 10.10.3 or newer running on a 2010 or newer Mac, with Intel’s hardware support for MMU virtualization; use Docker Toolbox if software or hardware requirements are not met.

Check out Docker for Mac vs. Docker Toolbox to understand the differences.

  • Install Boot2Docker package (I have installed Boot2Docker-1.7.0.pkg)
  • Start instance sharing folder /users/sdevarapalli/learning/docker as “shared”
    ws@sdevarapalli:~> boot2docker --vbox-share="/users/sdevarapalli/learning/docker=shared" up
    
  • Set up environment variables
    ws@sdevarapalli:~> eval "$(boot2docker shellinit)"
    Writing /Users/sdevarapalli/.boot2docker/certs/boot2docker-vm/ca.pem
    Writing /Users/sdevarapalli/.boot2docker/certs/boot2docker-vm/cert.pem
    Writing /Users/sdevarapalli/.boot2docker/certs/boot2docker-vm/key.pem
    ws@sdevarapalli:~> env | grep -i docker
    DOCKER_HOST=tcp://192.168.59.103:2376
    DOCKER_TLS_VERIFY=1
    DOCKER_CERT_PATH=/Users/sdevarapalli/.boot2docker/certs/boot2docker-vm
    
  • Log in to the server
    ws@sdevarapalli:~> boot2docker ssh
     ## .
     ## ## ## ==
     ## ## ## ## ## ===
     /"""""""""""""""""\___/ ===
     ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
     \______ o __/
     \ \ __/
     \____\_______/
     _ _ ____ _ _
    | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
    | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
    | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
    |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
    Boot2Docker version 1.12.0, build HEAD : e030bab - Fri Jul 29 00:29:14 UTC 2016
    Docker version 1.12.0, build 8eab29e
    docker@boot2docker:~$
    
  • To automatically mount the shared folder, add the script bootlocal.sh on the boot2docker host. This script gets executed on VM startup.
    docker@boot2docker:/mnt/sda1/var/lib/boot2docker$ cat bootlocal.sh
    sudo mkdir -p /mnt/shared
    sudo mount -t vboxsf shared /mnt/shared
    docker@boot2docker:/mnt/sda1/var/lib/boot2docker$
    
  • Commands to check status and shutdown:
    ws@sdevarapalli:~> boot2docker status
    running
    ws@ sdevarapalli:~> boot2docker stop