DEV Community

Cover image for How to Deploy a set of Microservices with a specified version using Docker?
Ajeet Singh Raina for Docker

Posted on

How to Deploy a set of Microservices with a specified version using Docker?

You can create a script (bash or python) to deploy a set of microservices with specified versions and parameters using the docker command.

Here's an example of a bash script that takes the version_service1 and version_service2 as arguments and deploys the corresponding microservices:

#!/bin/bash

# Get the version of service1
version_service1=$1

# Get the version of service2
version_service2=$2

# Get any additional parameters
additional_param_1=$3

# Start service1 with the specified version
docker run -d --name service1 myregistry/service1:$version_service1 --additional_param_1=$additional_param_1

# Start service2 with the specified version
docker run -d --name service2 myregistry/service2:$version_service2
Enter fullscreen mode Exit fullscreen mode

You can execute the script with the command:

./deploy.sh v1.0 v1.0 5
Enter fullscreen mode Exit fullscreen mode

This script will run the two microservices with specified versions and pass the additional parameter to the service1.

You can also create a similar script using python, for example, using the subprocess module to run the docker command and passing the arguments to the script.

It's important to note that this script runs the microservices on detached mode and name them service1 and service2. You can also use a more advanced approach like using docker-compose to deploy multiple services and manage them together, and use a .yml file to define the services, their versions, and their parameters.

Top comments (0)