Solution
The solution to exercise 4
We'll cover the following
Troubleshooting is really fun because you learn more while fixing issues and you may end up fixing extra issues generated by you while fixing an existing one.
Let’s walk through the solution and check whether you fixed exact issues or ended fixing new ones also.
Steps for basic troubleshooting
- Check for network connectivity between services
- Check for port mappings
- Check for any required volume mounts
- Check for valid image name to start services
- Check if the network used for connectivity exists
- Only supported are commands
- Check for any application-specific issues such as env variables or init scripts
Issues in services
We will go through one service at a time.
Web
In web services,
- The very first thing we can see is the
links
keyword. In swarm mode, instead oflinks
, we should usenetworks
to establish communication between services. So, removelinks
and write
networks:
- app
to connect the database to the app.
- What we need to do next is not an issue if you can increase replicas using
deploy
keyword and a specified number of replicas there.
Database
Many things are missing in this service. So, let’s go through using our troubleshooting steps, step by step.
-
We see that there is no connectivity for the database service as there is no
networks
keyword specified. -
Port mapping is not required as we are not accessing the database from the host.
-
We need to mount the volume as we need to pass our init script to Docker’s initdb.d folder.
-
Next, our Flask app will be exiting frequently since the database is not configured accordingly. So, pass the env file to start the database with the configuration used in the Flask app.
This will fix all the issues with the database service.
Visualizer
In the visualizer service,
- Network connectivity is not established using
networks
. So, addnetworks
. (Optional. The visualizer service continuously captures the status of other containers using the docker socket mounted in volume instruction. The network instruction will just make the visualizer container reachable to other containers in the network. )
That’s it. There are no more issues here.
After fixing all these issues, hit the run button or deploy the stack if you are running it on a local machine.
You will be able to access the visualizer which will show you a continuous state of swarm cluster.
Change app.config[‘MYSQL_HOST’] = ‘database’ in
app.py line 10
. Because links are not supported in docker stacks and services are identified with their service name mentioned in thedocker-compose.yml
file.
Get hands-on with 1400+ tech skills courses.