Appearance
Prepare Your Application for Deployment
To deploy an application, create a Docker image and a Docker Compose file. The image packages the software; the Compose file tells Mesh of Things which services to run on each assigned device.
TIP
The Compose editor in the dashboard includes a starter definition.
If you are unfamiliar with containers, there are plenty of resources available, and the guide below will walk you through the basics.
At the end of this page, there are also some useful resources if you need more help learning about Dockerfiles and Docker Compose.
Step 1: Create a Dockerfile
A Dockerfile contains the instructions used to build an image. The image includes your code, runtime, and runtime dependencies.
Here is an example of a simple Dockerfile:
dockerfile
# Use an official Python image
FROM python:3.11-slim
# Copy the current directory contents into the container at /app
COPY . /app
# Install any necessary dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Document the port used by the application
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]This example assumes you have a Python application with a requirements.txt file and an entry script called app.py alongside the Dockerfile. Modify the Dockerfile as needed to fit your application’s specific requirements.
Alternatively, use a suitable pre-built image from a registry such as Docker Hub. For example, this image serves static files with NGINX:
dockerfile
# Use the official NGINX image from the Docker Hub
FROM nginx:latest
# Copy the current directory contents into the container at /usr/share/nginx/html
COPY . /usr/share/nginx/html
# Expose port 80
EXPOSE 80This example uses the official NGINX image as a base and copies the current directory contents into the container at /usr/share/nginx/html, which is the default location for NGINX to serve files.
Step 2: Build and Push Your Docker Image
With your Dockerfile prepared, the next step is to build your Docker image and push it to a container registry like Docker Hub. This makes the image accessible for deployment across your Mesh of Things (MoT) network.
Build the Docker Image
Navigate to your application’s root directory (where the Dockerfile is located) and run the following command, where yourusername is your container registry username and your-app-name is the name of your application:
bash
docker build -t yourusername/your-app-name:v1.0.0 .Replace yourusername/your-app-name with the repository in your registry account. Prefer an immutable version tag, such as :v1.0.0, over :latest so a saved Compose version always identifies the same image.
Push to a Container Registry
Ensure you’re logged in to your container registry:
bash
docker loginTIP
If you’re using a different container registry like GitHub Container Registry or Google Container Registry, make sure to configure your credentials and URLs accordingly.
Then push the image:
bash
docker push yourusername/your-app-name:v1.0.0Once the image is in the registry, it’s ready to be referenced during deployment in your Compose file through the Mesh of Things platform.
Step 3: Create a Docker Compose File
Docker Compose allows you to define and manage multi-container applications in a single YAML file.
Here’s a basic example:
yaml
services:
web:
image: yourusername/your-app-name:v1.0.0
ports:
- '80:80'
environment:
- ENV=production
restart: unless-stoppedKey elements:
image: the image you previously pushed to the registry.ports: host-to-container port mappings, such as80:80.environment: environment variables required by the service. Store sensitive values under Variables and secrets in the dashboard rather than committing them to the Compose file.restart: an optional restart policy.
If your application depends on other services, like a database, you can define them too:
yaml
services:
web:
image: yourusername/your-app-name:v1.0.0
ports:
- '80:80'
db:
image: postgres:17
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}Create POSTGRES_PASSWORD as a secret under the app's Variables and secrets tab before deploying this example. Do not commit production credentials to a Compose file.
Once your Docker Compose file is ready, you're all set to proceed to deployment using Mesh of Things. Open the Apps page in the dashboard, create an app, and add your Docker Compose file as a version to deploy to devices.
Learning More
If you want to learn more about Dockerfiles and Docker Compose, here are some helpful resources: