Basic Docker swarm Operations

Docker swarm mode natively built on top of docker engine, So it’s easier to orchestrate and clustering capabilities on containers using docker swarm mode.

Following commands summarize basics of swarm mode operations.

Initialize a swarm
docker swarm init --advertise-addr <manager-ip-addr>

Swarm Status
docker info

List all swarm nodes
docker node ls

Get Swarm token to join as worker
docker swarm join-token worker

Get Swarm token to join as manager
docker swarm join-token manager

View all swarm services
docker service ls

Create a swarm service
docker service create --replicas 1 --name <name> <image> <command>

Inspect a running swarm service
docker service inspect --pretty <service-name>

Scale up/down a swarm service (increase/decrease replicas)
docker service scale <service-name>=<no-of-replicas>

Remove a swarm service
docker service rm <service-name>

Setup rolling update interval when creating service
docker service create --replicas 3 --name --update-delay 10s

Rolling Update running swarm service
docker service update --image <service-name>

Force Update stuck service updates without rolling manner
docker service update <service-name>

Filter swarm services by running state
docker service ps --filter="running" <service-name>

 

Hope this helps to get started with docker swarm. For more information:: https://docs.docker.com/engine/swarm/#feature-highlights

Enable MySQL Query Logs

I was using one of ORM tools inside my project suddenly I’ve faced a strange issue where it doesn’t do any interactions with MySQL. There’s NO errors on client side it seems queries never get executed so we wanted to listen connection/all queries coming to mysqld. I wanted to get a broader idea of what’s been going on.

I’ve checked MySQL manual and found concept of MySQL General Query Logging functionality which is spot-on for my requirement. I gave it a shot!.

This might be useful Anyone of you facing same situation as me.

MySQL General Query Log : https://dev.mysql.com/doc/refman/5.6/en/query-log.html

You can do this two ways,

1. Define in MySQL configuration file (my.cnf)
[mysqld]
general_log = on
general_log_file=/var/log/mysql/queries.log

You might need `mysqld` reloaded once add above lines of config.

2. MySQL Run-time via executing following queries
> set global general_log_file = "/var/log/mysql/queries.log";
> set global general_log = "ON";

Having Turn on MySQL query log might consume your hard drive space a lot. I would recommend to use whenever you needs it, Turn Off when you don’t needs it to avoid issues.

Personally I always recommend to use in Run-time so you can turn it off by executing following command.

> set global general_log = "OFF";

This might help!! Use it with caution.

Apache sets default Response charset

I’ve been currently working on a application that should render charset ISO-8859-1 to the browser.  So I’ve added a following meta tag to HTML document header.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

For some reason when rendering the page,  it always makes some characters broken or not been recognised. I’ve spend a good few hours to debug this situation thought it was due to some issue with application itself how it handles encoding.

Thanks to built-in browser “Inspect Element” tool, I’ve managed to crack down the root issue. It was causing this issue due to Response ContentType set to use charset UTF-8.

Content-Type:text/html; charset=utf-8

Application wasn’t setting ContentType charset in Response, Then where did this charset came from ?. HTML header meta tag wasn’t taking a effect in this case. It has overridden by Response ContentType charset.

-This is the time Apache took my attention.

It turned out that Apache was automatically sets AddDefaultCharset config directive to be UTF-8. It was automatically added to /etc/httpd/conf/httpd.conf by Default Installation.

AddDefaultCharset UTF-8

I’ve commented out  AddDefaultCharset directive form Apache config and reloaded Apache, it worked as expected.

I guess if you wanted to control encoding by application level then you should AddDefaultCharset Off or remove it from Apache config.

Hope this helps to solve unexpected encoding issues due to Apache config.