Docker Deployment
Deploying on Local Docker
Services created by sponge support Docker deployment. You can deploy your service in a Docker container on your local machine. Here are the detailed deployment steps:
Prerequisites
- Docker is installed on your local machine (Docker)
- The
docker-compose
command is installed (docker-compose)
Starting and Updating the Service
Switch to the service code directory
Execute the following command to build the image and run the service:
# Builds the image and runs the service in local Docker. To update the service, re-execute this command. make run-docker
The command
make run-docker
internally executes two commands: build image and run service. It also generates aconfigs
folder within thedeployments/docker-compose
directory under the service code directory. The configuration used by the service running in local Docker is the YAML configuration file within this folder.
Stopping the Service
# Switch to directory
cd deployments/docker-compose
# Stop the service
docker-compose down
Image Size Optimization
To reduce the image size, edit the scripts/image-build-local.sh
file, find the # compressing binary file
section, uncomment the code below it. This can reduce the image size by about 50%.
Deploying on Remote Server Docker
Sponge created services support convenient image building and pushing features.
Building the Image
Sponge services support two methods for building images: local compilation build and in-container compilation build.
Method 1: Local Compilation Build (Requires Local Go Environment)
Switch to the service code directory
Execute the command:
make image-build REPO_HOST=myRepo.com TAG=1.0
Method 2: In-Container Compilation Build (Does Not Require Local Go Environment)
Switch to the service code directory
Execute the command:
make image-build2 REPO_HOST=myRepo.com TAG=2.0
Configuration Notes
By default, Go version 1.23 is used. To modify this, edit the scripts/build/Dockerfile_build
file. Both methods can optimize image size by uncommenting the code below # compressing binary file
.
Image Push Guide
First, log in to the private repository:
docker login myRepo.com # Enter username and password as prompted
Push the image (ensure the REPO_HOST and TAG parameters match those used during build):
make image-push REPO_HOST=myRepo.com TAG=1.0
Alternative Method
You can also directly use the
docker push
command:docker push myRepo.com/edusys/user:1.0
Running the Service on the Remote Server's Docker
Package the scripts and configurations in the
deployments/docker-compose
directory under the service code and upload them to the remote server.# Package docker-compose scripts and service configurations tar -zcvf your_project_docker.tar.gz deployments/docker-compose # Upload to the remote server
Unpack the service configuration package to a specified directory on the remote server,
- Modify the image address in the
docker-compose.yaml
file. - Modify the configuration files in the
configs
folder.
- Modify the image address in the
Start the service:
# Switch to the extracted directory cd your_project_docker # Start the service docker-compose up -d
Stopping the Service
# Switch to directory
cd your_project_docker
# Stop the service
docker-compose down
```