Develop a Service with Docker¶
Choreo is a platform that allows you to create and deploy applications in any language.
In this guide, you will:
- create a containerized service component using a sample service implementation. The sample implementation will have a single resource named
greet
that accepts a single query parameter as input. - Deploy it in Choreo using a Dockerfile. The service will run on port 9090.
- Test the service.
If you want to create a service component that exposes a Ballerina service, see Develop a Ballerina Service .
Prerequisites¶
Before you try out this guide, complete the following:
-
If you are signing in to the Choreo Console for the first time, create an organization as follows:
- Go to https://console.choreo.dev/, and sign in using your preferred method.
- Enter a unique organization name. For example,
Stark Industries
. - Read and accept the privacy policy and terms of use.
- Click Create.
This creates the organization and opens the Project Home page of the default project created for you.
-
Fork the Choreo samples repository, which contains the sample greetings service implementation with the Dockerfile.
Learn the repository file structure¶
It is important to understand the purpose of the key files in the sample service. The following table provides a brief overview of each file in the greeter service:
Note
The specified file paths are relative to <sample-repository-dir>/greeting-service-go
Filepath | Description |
---|---|
main.go |
The Go-based greeter service code. |
Dockerfile |
The Dockerfile to build the container image of the application. |
.choreo/component.yaml |
Choreo-specific configuration that provides information about how Choreo exposes the service. |
openapi.yaml |
The OpenAPI contract of the greeter service. This is required to publish the service as a managed API. This openapi.yaml file is referenced by the .choreo/component.yaml file. |
Let's get started!
Configure the service port with endpoints¶
In Choreo, you can expose your services via endpoints.
You are going to run the greeter service on port 9090. To securely expose the service through Choreo, you must provide the port and other required information to Choreo. For detailed information on each attribute of an endpoint, see Configure Endpoints.
To configure the endpoint details of a containerized component, Choreo looks for an component.yaml
file inside the .choreo
directory. Be sure to place the .choreo
directory at the root of the Docker build context path.
In the greeter sample, the component.yaml
file is in the greeting-service-go/.choreo/
directory.
Step 1: Create a service component from a Dockerfile¶
To create a containerized service component, follow these steps:
- Go to https://console.choreo.dev/ and sign in. This opens the project home page.
- If you already have one or more components in your project, click + Create. Otherwise, proceed to the next step.
- Click the Service card.
-
Enter a display name, a unique name, and a description for the service component. You can enter the values given below:
Info
In the Component Name field, you must specify a name to uniquely identify the component in various contexts. The value is editable only at the time you create the component. You cannot change the name after you create the component.
Field Value Component Display Name Greetings
Component Name greetings
Description Send greetings -
Go to the GitHub tab.
-
To allow Choreo to connect to your GitHub account, click Authorize with GitHub. If you have not already connected your GitHub repository to Choreo, enter your GitHub credentials and select the repository you created in the prerequisites section to install the Choreo GitHub App.
Alternatively, you can paste the Choreo samples repository URL in the Provide Repository URL field to connect to it without requiring authorization from the Choreo Apps GitHub application. However, authorizing the repository with the Choreo GitHub App is necessary if you want to enable Auto Deploy for the component.
Note
The Choreo GitHub App requires the following permissions:
- Read and write access to code and pull requests.
- Read access to issues and metadata.
You can revoke access if you do not want Choreo to have access to your GitHub account. However, write access is exclusively utilized for sending pull requests to a user repository. Choreo will not directly push any changes to a repository.
-
Under Connect Your Repository, enter the following information:
Field Value Organization Your GitHub account Repository choreo-samples Branch main
-
Select Docker as the buildpack.
-
Enter the following information:
Field Value Docker Context /greeting-service-go
Dockerfile /greeting-service-go/Dockerfile
Info
-
To successfully build your container with Choreo, it is essential to explicitly define a user ID (UID) under the USER instruction in your Dockerfile. For reference, see sample Dockerfile. To ensure that the defined USER instruction is valid, it must conform to the following conditions:
- A valid User ID is a numeric value between 10000-20000, such as
10001
or10500
. - Usernames are considered invalid and should not be used. For example,
my-custom-user-12221
ormy-custom-user
are invalid User IDs.
- A valid User ID is a numeric value between 10000-20000, such as
-
The Dockerfile used in this guide is a multi-stage Dockerfile, which is designed to keep the final image size small and provides the ability to build the application with a specific version of tools and libraries.
-
-
Click Create. This creates the component and takes you to the Overview page of the component.
You have successfully created a service from a Dockerfile. Next, you can build and deploy the service.
Step 2: Build and deploy¶
Now that we have connected the source repository, and configured the endpoint details, it's time to build the service and create an image. Then we can deploy that image test the greeter service.
Step 2.1: Build¶
To build the service, follow these steps:
- In the left navigation menu, click Build.
-
On the Build page, click Build Latest.
Note
Building the service component may take a while. You can track the progress via the logs in the Build Details pane. Once the build process is complete, the build status changes to Success.
You can access the following scans under Build.
- The Dockerfile scan: Choreo performs a scan to check if a non-root user ID is assigned to the Docker container to ensure security. If no non-root user is specified, the build will fail.
- Container (Trivy) vulnerability scan: This detects vulnerabilities in the final docker image.
-
Container (Trivy) vulnerability scan: The details of the vulnerabilities open in a separate pane. If this scan detects critical vulnerabilities, the build will fail.
Info
If you have Choreo environments on a private data plane, you can ignore these vulnerabilities and proceed with the deployment.
Step 2.2: Deploy¶
To deploy the service, follow these steps:
- In the left navigation menu, click Deploy.
- On the Set Up card, click Configure & Deploy.
- In the Environment Configurations pane that opens, click Next to skip the configuration.
- In the File Mount pane, click Next to skip the configuration.
-
Review the Endpoint Details and click Deploy.
Note
Deploying the service component may take a while. Once deployed, the Development environment card indicates the Deployment Status as Active.
Once you have successfully deployed the service, you can test, manage, and observe it like any other component type in Choreo.
To perform a more detailed diagnosis of this Dockerfile-based REST API by viewing Kubernetes-level insights, see Choreo's DevOps capabilities.