Docker Cheat Sheet for Sysadmins

Docker Cheat Sheet for Sysadmins Docker Cheat Sheet for Sysadmins

Linking multiple containers

The example is shown for linking two containers. We need to run a WordPress site, for that let us prepare to launch two containers and link each other.

We are creating a dedicated network for web server and DB server.

# docker pull mariadb
# docker pull wordpress

# docker network create --subnet 192.168.107.0/24 --gateway 192.168.107.2 web_net
# docker run -d --name web_db --network web_net --ip 192.168.107.10 -e MYSQL_ROOT_PASSWORD=redhat123 -e MYSQL_DATABASE=web_db -e MYSQL_USER=redhat -e MYSQL_PASSWORD=redhat123 mariadb
# docker run -d --name web_srv --network web_net --ip 192.168.107.11 -e WORDPRESS_DB_HOST=web_db:3306 -e WORDPRESS_DB_USER=redhat -e WORDPRESS_DB_PASSWORD=redhat123 -e WORDPRESS_DB_NAME=web_db -e WORDPRESS_TABLE_PREFIX=wp_docweb --link web_db -p 8080:80 wordpress

Working with Docker Swarm

To initialise the swarm use “swarm init

# docker swarm init --advertise-addr 192.168.107.136 --listen-addr 192.168.107.136:2377

Output for reference.

[root@docker ~]# docker swarm init --advertise-addr 192.168.107.136 --listen-addr 192.168.107.136:2377
 Swarm initialized: current node (63qud8ovv00aqaws072oxxa9h) is now a manager.

 To add a worker to this swarm, run the following command:

 docker swarm join --token SWMTKN-1-48q24en6jyyi6nvjmrdukzlr5h20n0rtrzcvdveo67l0n9zyh3-2japtts5gppa1q3zdvkfbiabf 192.168.107.136:2377

 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

 [root@docker ~]#

Allow the firewall for port 2377.

# firewall-cmd --add-port=2377/tcp --zone=public --permanent
# firewall-cmd --reload
# firewall-cmd --list-all

Back to worker node client1.linuxsysadmins.local and run below command to join the swarm as a worker.

# docker swarm join --token SWMTKN-1-48q24en6jyyi6nvjmrdukzlr5h20n0rtrzcvdveo67l0n9zyh3-2japtts5gppa1q3zdvkfbiabf 192.168.107.136:2377

Output for reference

[root@client1 ~]# docker swarm join --token SWMTKN-1-48q24en6jyyi6nvjmrdukzlr5h20n0rtrzcvdveo67l0n9zyh3-2japtts5gppa1q3zdvkfbiabf 192.168.107.136:2377
 This node joined a swarm as a worker.
[root@client1 ~]# 

List the joined worker nodes from the manager.

# docker node ls

Output for reference

[root@docker ~]# docker node  ls
 ID                            HOSTNAME                       STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
 kaqbo9t94vhactbuavpo60wno     client1.linuxsysadmins.local   Ready               Active                                  18.09.7
 63qud8ovv00aqaws072oxxa9h *   docker.linuxsysadmins.local    Ready               Active              Leader              18.09.7
 [root@docker ~]#

To leave from Swarm

# docker swarm leave
# docker swarm leave --force

Will update soon with more commands in this docker cheat sheet.

Conclusion

Docker Cheat Sheet for sysadmins will be updated frequently whenever we use something in production. Subscribe to our newsletter and stay with us for future updates.