Dockerize the Service

Why do I need Docker ?

Services run in Docker to provide a sandbox and a normalized environment to remove any side effects that may occur when running on many different machines. See more information on the Docker website.

Steps to be compatible with Docker

Create the Dockerfile

In order to be compatible with Docker, a Dockerfile needs to be created in the folder of the service. See the Dockerfile reference.

Examples

FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm", "start" ]

Check out how to dockerizing a Node.js web app.

FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]

Check out how to build a minimal Docker Containers for Go applications.

Add a configuration and dependencies

TIP

Configuration and dependencies are an advanced feature and your service might not need this. This is totally optional and really depends on your service needs.

Once the Service can run on Docker, Core should be able to start it automatically. Update the mesg.yml file with the config. and optional dependencies the service needs.

The configuration key is a Dependency object that will be use to configure the main Docker container of the service. All Dependency attributes are available except image. The attribute image will be set automatically when the service is deployed.

If the service requires dependencies to other Docker container, specify them in the dependencies map.

Definitions

Attribute Type Description
image String The docker image of the Service. Only available for dependencies.
volumes array[string] A list of volumes that will be mounted in the Service.
ports array[string] A list of ports that the Service needs to expose.
command String The command to run when the Service starts if not defined in your Dockerfile.
volumesfrom array[string] List of dependencies' names to mount a volume from.

Example

name: serviceX
tasks: {}
events: {}
configuration:
  command: "node start"
  volumesfrom:
    - serviceToConnectWith
dependencies:
  serviceToConnectWith:
    image: "..."
    volumes:
      - "/tmp"
    ports:
      - "1234"

Each dependency's key is used as its hostname on the shared network between the service and dependencies. In this example, the service can access the dependency at the endpoint serviceToConnectWith:1234.

Get Help

You need help ? Check out the MESG Forum.

Last Updated: 1/31/2019, 9:33:18 AM