-
Notifications
You must be signed in to change notification settings - Fork 3
The GPL Docker
This projects builds docker images on alpine OS. The images are on gcr.io/the-gpl
in Google
Container Registries.
The Alpine from Google it is lightest and fastest golang docker environment.
These are build it two ways:
- Using GCP cloud build as part of CICD pipeline.
- From Mac command line
The git repo is configured to trigger Cloud Build when git push origin master
is executed. The build steps
are outlines in cloudbuild.yaml. It works along with Dockerfile.
The cloudbuild.yaml
and Dockerfile
is used by Google Cloud Build to create container
image tag and stores it to gcr.io/the-gpl/book
.
The Mac commands to create docker image on local laptop are:
- GCloud container images
- Docker Hub repository
From your laptop is gcloud
command line to build the image.
# Build GCP container image using Cloud Build
gcloud builds submit --tag gcr.io/the-gpl/gpl:v1
gcloud container images list --repository=gcr.io/the-gpl # Show your container registries
From your laptop is docker
command line to build the image.
# Build on local docker
docker build -t the-gpl:v1 . # Build version v1
docker image ls # See docker images
docker history the-gpl:v1 # See image layers
docker image inspect the-gpl:v1
The images are deployed on:
- GCR.io i.e. Google Cloud Registry, and
- Docker hub.
The cloudbuild.yaml
contains deployment instructions to GCP cloud.
To deploy as Cloud Run service use the GCP console to create service for docker image.
You can use these gcloud
commands.
gcloud auth login # Ensure you are logged to your GCP cloud project account
gcloud config set project the-gpl # Make sure you are in right project
gcloud run deploy --image gcr.io/the-gpl/gpl:v4 --platform managed --allow-unauthenticated # Deploy
The image is also on docker repository. In order to push images to docker repo commit it, add tag and push. e.g:
docker tag the-gpl:v1 uopendocker/the-gpl:v1
docker push uopendocker/the-gpl:v1
You can build a image with specific tag and run it in local docker container.
docker build -t the-gpl:v1 . # Build version v1
docker image ls # See docker images
These commands will come handy to use docker in your environment.
Use the --rm
to run docker images.
# Sample cloud run examples, remove container after run
docker run --rm the-gpl:v1 ./the-gpl mas -fn=array
docker run --rm the-gpl:v1 ./the-gpl mas -fn=slice
docker run --rm the-gpl:v1 ./the-gpl mas -fn=comp -n1=123 -n2=-1234
docker run --rm the-gpl:v1 ./the-gpl fetch -site=http://www.google.com -site=http=//www.facebook.com
docker run -d -p 8080:8080 the-gpl:v1 ./the-gpl server -port=8080
Here are docker container commands.
docker container ls # See all your containers
docker container ps -a # Your docker process
docker container prune # Remove stopped containers
docker stop 58a639eecb9a # '58a639eecb9a' is the container id of image "the-gpl"
dcoker rm 58a639eecb9a # Remove container with id '58a639eecb9a'
Make sure to prune your containers and images:
docker image rm image:version # Remove unused images
docker container prune
docker image prune
You can create your own local log file by mounting it to docker container.
# If you like to log to a file.
export DEV_LOGS="~/Logs/DevLogs/"
docker run -d -p 8080:8080 -v $DEV_LOGS:/app/logs the-gpl