Skip to content

Deploying Go application to AWS ECS(EC2 launch type) using Docker via CI/CD Pipeline.

License

Notifications You must be signed in to change notification settings

Big-Vi/go-ci-cd

Repository files navigation

Docker

  • Create Dockerfile and Dockerfile.production
  • Build Docker production image using multi-stage builds
  • Add Docker compose and Makefile for easy of use
  • Since the Go app and Postgres running in separate container, shared network needs to be created. The name of the network can be referenced rather than the IP which is not permanent.

Useful Docker commands

  • To list images

      docker image ls
  • To tag image

      docker image tag go-ci-cd:latest go-ci-cd:v1.0
  • To remove the tagged image

      docker image rm go-ci-cd:v1.0
  • To publish port of container add --publish flag and add --detach flag to run in detached mode

      docker run --detach --publish 8000:8000 go-ci-cd
  • To list all containers

      docker ps -all
  • To stop, restart & remove container

       docker stop <CONTAINER_ID>
       docker restart <CONTAINER_ID>
       docker rm <CONTAINER_ID>

Push Docker image to Amazon ECR using CLI

  • To login to ecr
       aws ecr get-login-password --region ap-southeast-2 | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.ap-southeast-2.amazonaws.com
  • Tag your local Docker image
           docker tag <IMAGE_ID> <ACCOUNT_ID>.dkr.ecr.ap-southeast-2.amazonaws.com/golang
  • Before pushing the image to ECR, create repository named as golang in AWS.
           docker push <ACCOUNT_ID>.dkr.ecr.ap-southeast-2.amazonaws.com/golang

About

Deploying Go application to AWS ECS(EC2 launch type) using Docker via CI/CD Pipeline.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published