Skip to content
Branch: master
Find file History

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

Sample9: Docker Hello World Function

  • This sample runs simple ballerina main function in a docker container.
  • The service is annotated with @docker:Config{} and docker:CopyFile annotations.
  • Default values for docker annotation attributes will be used to create docker artifacts.
  • Following files will be generated from this sample.
    $> docker image
    $> tree
    ├── copy_file_function.jar
    └── docker
        └── Dockerfile

How to run:

  1. Compile the copy_file_function.bal file. Command to run docker image will be printed on success:
$> ballerina build copy_file_function.bal
Compiling source

Generating executables

Generating docker artifacts...
        @docker                  - complete 2/2 

        Run the following command to start a Docker container:
        docker run -d copy_file_function:latest
  1. copy_file_function.jar, Dockerfile and docker image will be generated:
$> tree
├── copy_file_function.bal
├── copy_file_function.jar
└── docker
    └── Dockerfile
  1. Verify the docker image is created:
$> docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
copy_file_function    latest             df83ae43f69b        2 minutes ago        102MB
  1. Run docker image as a container (Use the command printed on screen in step 1):
$> docker run -d copy_file_function:latest
  1. Verify docker container is running:
$> docker logs 68eb4160ac769f131ebd3ed59f8ee0f6fe6a2e1924e290b04a4cd7513e9b71d1
{'userId': '', 'groups': 'esb'}
Lorem ipsum dolor sit amet.
  1. Remove docker instance and image.
$> docker rm -f 68eb4160ac76
$> docker rmi copy_file_function:latest
You can’t perform that action at this time.