Running a simple client server program in docker

Looks like you’re pretty close, just need to revise a bit to fit Docker’s networking model.

I’d suggest creating a user-defined network and using that to connect them. You can access containers in the same network via DNS entries (one for each container name).

Here’s an example to explain. In your case you will configure the client container to connect to the server DNS entry server (similar to how myserver is used below).

$ docker network create javaapp
451905b63038719be32c3029dd229d02260fdc6f5fcca136c063556d3f3714d4

$ docker run -d --net javaapp --name myserver nginx
4b8c235789b2b262190f39d1ca2495304ca4ffc84321a127ac1bb9a0b748c717

$ docker run --net javaapp nathanleclaire/curl curl myserver:80
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
100   612  100   612    0     0    120      0  0:00:05  0:00:05 --:--:--   99k
1 Like