Deploying microservices with Docker

Now, with Docker images being built and the Docker composing layout defined, it is possible to build the composing layout and start it so that it can cater requests. The following command, issued from inside the spring-boot-2-taxi project, composes everything:

$ docker-compose build

The preceding command will generate a somewhat familiar output:

db uses an image, skipping
Building taxi-booking-service-app
...
Successfully built 8e77b030d54c
Successfully tagged spring-boot-2-taxi_taxi-booking-service-app:latest
Building taxi-service-app
...
Successfully built a2f9c5cf28af
Successfully tagged spring-boot-2-taxi_taxi-service-app:latest
nginx-lb uses an image, skipping

The preceding output shows that db and nginx-lb use an existing image, so they are not built from scratch, whereas taxi-booking-service-app and taxi-service-app are built from scratch using the Dockerfile and initialize everything.

Next, the following command can be used to start all the Docker containers of the system:

$ docker-compose up -d

The preceding command will create all the containers in daemon mode (will run in the background) and will generate the following familiar-looking output:

Creating network "spring-boot-2-taxi_backend" with driver "bridge"
Creating spring-boot-2-taxi_db_1 ... done
Creating spring-boot-2-taxi_taxi-service-app_1 ... done
Creating spring-boot-2-taxi_taxi-booking-service-app_1 ... done
Creating nginx-lb ... done

As explained earlier, the output shows that the network is being created first, followed by db, followed by the apps, and finally nginx load balancer.

Individual apps can be scaled up or down using the following command:

docker-compose up --scale <APP_NAME>=2 -d

APP_NAME can be either taxi-service-app or taxi-booking-service-app based on the requirement. The number after the equals sign depicts the number of containers required to be running for that app.

Consider the following example:

docker-compose up --scale taxi-service-app=2 -d

Also, in order to stop and bring down all the services started, the following command can be used:

docker-compose down
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.233.153