Getting started with Docker
Great news!! Since v0.10 release aah framework brings support for Docker Image on Docker Hub and aah CLI command for Dockerfile
generation.
aah has automated build process for Docker Image creation. Supported Docker tags are -
aahframework/aah:latest
- Latest production release.aahframework/aah:{version}
- Specific release version, for e.g.:aahframework/aah:v0.9
.aahframework/aah:edge
- Latest development edge version.
Note:
- aah framework docker base image is
golang:latest
. - Ensure to install Docker on your machine.
Table of Contents
Pull aah Docker Image
Pull docker image from Docker Hub.
# Pull latest production release
docker pull aahframework/aah:latest
# Pull edge version
docker pull aahframework/aah:edge
# Pull specific version
docker pull aahframework/aah:v0.9
Handy generate
Command
aah CLI includes generate
command to help developers in their application development path. This command generates two
docker files -
Dockerfile.dev
- For development usage with aah docker image.Dockerfile.prod
- Using Multistage-build to create very small docker image for production purpose. More info, refer to https://docs.docker.com/develop/develop-images/multistage-build/.
Note: aah CLI provides very good starter Dockerfile(s) for your application, enhance it per your need.
Example
# run from anywhere
aah generate script --name docker --importpath github.com/user/appname
# OR if you're in app directory or path
aah generate script --name docker
# OR short form
aah g s -n docker
Using Dockerfile.*
To Build Docker Image
# Using Dockerfile.dev
docker build --no-cache -t "yourapp:dev" -f Dockerfile.dev .
# Using Dockerfile.prod
docker build --no-cache -t "yourapp:latest" -f Dockerfile.prod .
Running built Docker Image
# To run Dockerfile.dev image
# To stop press Ctrl + C
docker run -it -p 8080:8080 "yourapp:dev" aah run
# To run Dockerfile.prod image
# To stop, do it via container stop
docker run -p 8080:8080 "yourapp:latest"
Compile your app inside the Docker container
There might a occasions you would like to build your application inside the container and get the build artifact. You can write something like:
docker run --rm -v "$PWD":/go/src/github.com/user/appname -w /go/src/github.com/user/appname aahframework/aah:latest aah build