Docker on Amazon AWS

· docker amazon aws centos

This is a short tutorial about getting Docker running on AWS Ubuntu. I’ve done this as I found that boot2docker was using a lot of memory and CPU on my laptop, and port forwarding is a pain. As I already have a free instance on Amazon AWS, I can use this.

(1) Get an Amazon EC2 instance and install Ubuntu on it.

I found it useful to put an alias into my ~/.ssh/config with all the keys etc set-up so I can connect just using ssh ec2.

(3) Install Docker

apt-get -y install docker.io

(4) Start Docker

By default, Docker is a daemon., but I want to use mine for development, but shut down when done.

service docker.io stop

I want to set-up port forwards. So I run a command to connect to the EC2 instance and start the daemon, so I run this from my local machine:

ssh -t -L8080:localhost:8080 -L4243:localhost:4243 ec2 sudo docker -d -D -H tcp://127.0.0.1:4243

This command does a few things:

When you’re done, ctrl+c to shut it down.

(5) Test

You probably want to perform some basic smoke tests. You’ll need to set-up an environment variable:

export DOCKER_HOST=tcp://localhost:4243

Pull an image:

docker pull centos

Run a simple command:

docker run -t -i centos echo 'Hello world!'

Download from a repo:

docker run -t -i centos yum -y install ping