Getting started with Docker

aah CLI provides command to generate Dockerfile for development and production purpose. aah provides very good starter Dockerfile(s) for your application, enhance it per your use case.

Ensure to install Docker on your machine.

Note: Since v0.12.0 aah does not provide docker images aahframework/aah:* in-favor of Go modules.

Table of Contents

Handy generate Command

Introduced in v0.10.0 aah CLI. Command generate is to help developer(s) in their application development path. It generates two docker files -

  • Dockerfile.dev - For development purpose.
  • Dockerfile.prod - Uses Multistage-build to create very tiny docker image for production purpose.

Example

# Go to application base directory and run
aah generate script --name docker

# OR shorthand
aah g s -n docker

Using Dockerfile.{dev, prod}

Various sample usage commands.

To Build Docker Image

# Using Dockerfile.dev
docker build --no-cache -t "your-app-image-name:dev" -f Dockerfile.dev .

# Using Dockerfile.prod
docker build --no-cache -t "your-app-image-name:latest" -f Dockerfile.prod .

Running built Docker Image

# Run docker image created using `Dockerfile.dev`
# To stop: press Ctrl + C
docker run -it -p 8080:8080 "your-app-image-name:dev" aah run

# Run docker image created using `Dockerfile.prod`
# To stop: do it via container stop
docker run -p 8080:8080 "your-app-image-name:latest"