41780

docker container in same network cannot reach other container in same network

Question:

I'm using ubuntu 15.10 on digital ocean

The following works docker network create a

docker run -d --name=nginx --net=a nginx

docker run -it --net=a --name web node bash

apt-get install -yq curl && curl nginx

The opposite, trying to reach the web container from the nginx container, does not work for me.

I go into the web container: docker exec -it web bash

Then I add my index.html file

Then I use http-server to serve an index.html file with the command http-server ./ -p 4200 -a 0.0.0.0 index.html.

http-server returns:

Starting up http-server, serving ./ Available on: http:127.0.0.1:4200 http:172.17.0.5:4200 Hit CTRL-C to stop the server

If I then go into nginx and try curl web:4200 then I get curl: (7) Failed to connect to web port 4200: Connection refused

Answer1:

Spun up a fresh Ubuntu 15.10 droplet on DigitalOcean and trying to reproduce this;

Using the quick n dirty curl | sh install method - not best practice, but heck, it's easy:

apt-get install -y curl && curl -fsSL https://get.docker.com | sh

Create network mynetwork and containers weba and webb on that network;

docker network create mynetwork docker run --net mynetwork --name weba -d node sh -c 'npm install http-server -g && mkdir -p /public && echo "welcome to weba" > /public/index.html && http-server -a 0.0.0.0 -p 4200' docker run --net mynetwork --name webb -d node sh -c 'npm install http-server -g && mkdir -p /public && echo "welcome to webb" > /public/index.html && http-server -a 0.0.0.0 -p 4200'

Reach webb from inside weba

docker exec -it weba sh -c 'curl http://webb:4200' # welcome to webb

Reach weba from inside webb

docker exec -it webb sh -c 'curl http://weba:4200' # welcome to weba

That looks to work for me; is there anything different on your environment?

Answer2:

This is a good time to question whether you network isolation is an important part of why you are using containers.

Consider avoiding the issue by running your containers on the same network as the Host OS.

On modern Linux systems running systemd, you have access to the systemd-nspawn container solution, without installing any additional software. It provides process isolation, resource management, chroot'ed environments, and the ability to share the Host OS network with the <a href="https://wiki.archlinux.org/index.php/Systemd-nspawn#use_host_networking" rel="nofollow">--network-veth</a> option.

Recommend

  • docker container as gateway between two docker bridges
  • Hyperledger Fabric v0.6 using Docker Toolbox
  • Having trouble passing PFUser as a PFObject
  • Mosquitto reload config file
  • Failed to submit local jar to spark cluster: java.nio.file.NoSuchFileException
  • How to use diff and patch in Cygwin on Windows?
  • What is “the regular file” on CentOS and Ubuntu?
  • Apache graceful restart - Does it affect current PHP script execution
  • Why does Perl's IO::Socket on Windows complain about “Resource Not Available” after 64 connecti
  • Open a Configuration Profile through app
  • Docker nginx reverse proxy gives “502 Bad Gateway”
  • The C Programming Language K&R exercise 1- 9
  • Getting socket.io namespace from anywhere in the project
  • Issue when joining serf nodes located in different Docker containers
  • Getting zero results in search using elastic4s
  • c++ search a vector for element first seen position
  • Setting src to Base64-encoded image with Javascript is failing
  • NSMutableArray instance used in a block
  • Is there any purpose for h2-h6 headings in HTML5?
  • XOR with Neural Networks (Matlab)
  • pymongo replication secondary readreference not work
  • Calculating ratio of reciprocated ties for each node in igraph
  • How to create CGPath from a SKSpriteNode in SWIFT
  • Generate random number from custom distribution
  • Mysterious problem with floating point in LISP - time axis generation
  • iOS: Detect app start via notification press
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Fill an image in a square container while keeping aspect ratio
  • Rearranging Cells in UITableView Bug & Saving Changes
  • how to add data labels for bar graph in matlab
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • Reading document lines to the user (python)