Lightsail And Docker
As Incode Software we’ve been starting to "dockerize" our applications, and with the advent of Amazon Lightsail I thought I’d quickly try to put it all together.
Here’s the steps:
-
Sign up for Lightsail
-
set up ssh
-
from the Lightsail account page, create a private key, and download the
.pem
file -
using puttygen (or similar) load the
.pem
file thenConversions > Export OpenSSH key
to create theid_rsa
file -
copy
id_rsa
to~/.ssh
andchmod +400 ~/.ssh/id_rsa
-
-
create an instance
-
base OS: Ubuntu 16.04
-
(as per this blog post), specify this launch script:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 \ --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | \ sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual sudo apt-get install -y docker-engine sudo service docker start
-
specify the ssh key pair created in previous step
-
specify instance plan ($5 a month may well suffice)
-
-
create a static IP address and assign to the instance
-
start the instance
-
(optionally), restart the instance (because of changes required after all that startup stuff).
Next:
-
ssh into the instance, eg:
ssh ubuntu@34.194.220.87
-
run up postgres backend (already uploaded to dockerhub):
sudo docker run --name postgres -d incodehq/postgres
The dockerhub/incodehq/postgres image is built using the
Dockerfile
from github/incodehq/docker-postgres. -
run up the example isis app (already uploaded to dockerhub):
ISIS_OPTS="" ISIS_OPTS=$ISIS_OPTS+"isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionDriverName=org.postgresql.Driver" ISIS_OPTS=$ISIS_OPTS+"||isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionURL=jdbc:postgresql://db:5432/incodehq" ISIS_OPTS=$ISIS_OPTS+"||isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionUserName=incodehq" ISIS_OPTS=$ISIS_OPTS+"||isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionPassword=incodehq" sudo docker run \ --name isis-app-dockertest \ --link postgres:db \ -e ISIS_OPTS=$ISIS_OPTS \ -p 80:8080 \ -d incodehq/isis-app-dockertest
The dockerhub/incodehq/isis-app-dockertest image is built using the
Dockerfile
from github/incodehq/docker-isis-app-dockertest, which in turn has a copy of the WAR file as built from github/isisaddons/isis-app-dockertest app.
The app is exposed on port 80, so you should be able to access the app from a browser, eg: http://34.194.220.87