Sidecar Tutorial: Docker & Deploy
Last updated
Last updated
The last step in configuring the application is to containerise the app with Docker. First we create a Dockerfile
for the server-side API and the client-side app then compose a build using the demonstrated docker-compose.yml
file available below.
Add the Dockerfile
to the server directory.
The server-side API will run on port 5000, the client-side application will call the API for requests on this designated port.
Add the Dockerfile
to the app directory.
The docker-compose.yml file will be composed of three sections.
FastAPI - Server-side API, run on port 5000. Container is named 'fastapi' as the name suggests.
Vue/Nuxt js - Client-side application named frontend, run on port 80. Running the client-side app on port 80 will allow for automatic rerouting to port 443 while adding an ssl certificate to your application rather than having it run on another port and require a configuration for a reroute to port 80 later on.
Sidecar - Connects the application to IndustryApps with your unique credentials.
Inside the docker-compose.yml
file, add the necessary information which is tagged with curly braces ' { }
'.
IP
-> The IP of the web service which you are running, such as on AWS EC2 Ubuntu, Lightsail instance or Azure Web services as an example.
PORT
-> The port which the app client-side is served at (e.g. Port 80).
APPCODE
-> Navigate to your Developer dashboard > Applications > {App Name} > App Data, the Application code will be available there.
HOSTNAME
-> The domain of the application such as:
https://sample-app.com/<<AppCode>>
.
Once the docker-compose has been updated accordingly, the app can be run by:
Building the container:
docker-compose build
Run the container:
docker-compose up
The application will need to be connected with a hostname which is ssl certified. There are various affordable or free options available to upload your application to a web service to accommodate this requirement.
For this tutorials purpose you can use AWS Lightsail, which offers Ubuntu Instances. After you've registered with AWS:
The Lightsail instance can receive a free certificate from AWS ACM which can be used by the Elastic load balancer.
The load balancer can connect to your Lightsail instance by enabling VPC peering on your Lightsail Instance then copying the Lightsail instance Private IP into the elastic load balancer which has the ssl certificate.
Once the web service instance has been configured, the built application can be moved to the web service instance through scp which is a secure copy with directory structure kept.
Example:
Once the application has been setup in the appropriate environment, by running the docker-compose commands, a status code 204 showing successful registration should notify the app has been connected.