Docker to Docker Networking Between TCP Client and Server

DZone 's Guide to

Docker to Docker Networking Between TCP Client and Server

This article presents a step-by-step instructions on how to create a TCP client and server for IoT applications using Docker containers and networking.

· Cloud Zone ·
Free Resource


Take a look at how two containers communicate

A TCP-based client and server are a frequently needed setup in IoT-based applications.

Presented in this article are:

  1. A method to create a Java-based client and server to send and receive binary data
  2. The client and server, each run inside a Docker container and communicating through Docker networking.

You may also enjoy: Understanding Docker Networking

Create a TCPClient.java as per the code provided below


Create a manifest file for the TCPClient as is shown below:


Create a Dockerfile for TCPClient as below:


Create a TCPServer.java as per the code provided below:


Create a manifest file for TCPServer as below:


Create a Dockerfile for TCPServer as below


The directory structure should be as displayed as shown below:

Directory structure

Run the following commands at the unix prompt:


Create the network:


Run the server:


Run the client:



You should see the client output as shown below:

Client output

And the server output should be as shown below:

Server output

containers, docker, docker networking, networking, tcp, tcp protocol, tcp server

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}