Before we start please review the two post before we start
- The Ultimate guide to DevOps Tools Part #1 : Docker here
- Talking about docker concept , how install it.
- The Ultimate guide to DevOps Tools Part #2 : Docker here
- how to build your first application using docker
- In this post i will talk about Docker Services.
as already mentioned above this post i will describe the level up about docker which is services which mean scale the application and enable load-balancing.
When i will need to create a services ?
Regarding to Docker Documentation here
To deploy an application image when Docker Engine is in swarm mode, you create a service. Frequently a service is the image for a microservice within the context of some larger application. Examples of services might include an HTTP server, a database, or any other type of executable program that you wish to run in a distributed environment.
But First Let’s Understand what is the docker services ?
Simply It’s group of containers of the same image, services will make your life easier when you are planning to scale your application also it will be working on docker cloud, to do that you should configure the service in three steps:-
- Choose a Container Image.
- Configure the Service.
- Set Environment variables.
Before configure any docker services there is file called “docker-compose.yml” it’s define how the docker container will behave in the environment.
the below example show you how the file looks like ( taken from docker documentation), at the first look you will understand anything but luckily it’s very simple and easy to understand it.
Let’s discuss the above file :-
- username/repo:tag –> should be replaced by your image information.
- run the same image as 5 instance and the main name will be “web”.
- Limitation will be 10% of CPU and 50 MB for each instance.
- the instance will be restarted on failure.
- mapped to port 4000 outside of docker, 80 inside the image.
- the load balancer will be mapped also on port 80 as you see from network section called webnet.
The Real Work :-
Before anything you should run the following command to be able to work and deploy your services
But in case you are facing the below issue
you have to upgrade your docker as method number#1 or uninstall it then install the newer version, after doing that and make sure you run the above command to ensure you will not get any error like “this node is not a swarm manager.” you can run the next command that allow you to create services.
where myfirstapp is my application name.
Get the ID for the one service in our application:
Several times in a row, or go to that URL in your browser and hit refresh a few times.