Network problem inside a Docker container

Last weeks me and couple of folks from my team have started using Docker. So every one of us was a Docker-newbie. And I have noticed all of us had the same common problem:

Network connections were not working inside a Docker while they were fine on a host running the Docker container.

Example: I wanted to build a Docker image based on the following Dockerfile:

FROM debian:9.2
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y maven
RUN apt-get install -y gradle

My command to build an image:
docker build -t java8_maven_gradle .

It failed as soon as it started executing the apt-get update command. None of other commands making network requests was running as well.

After some surprisingly long search in the Internet I found out that a Docker container by default has networking turned off. That explained our problems. The solution was to add
--network=host
parameter to commands invoking Docker. So my command became:
docker build --network=host -t java8_maven_gradle .

I used version 17.xx of Docker. Some older versions of Docker do not recognize --network parameter. Instead they need -net.

Afterwords

I suppose this is something obvious for people knowing Docker well. However it looks like people that need to just quickly start using Docker without devoting a longer time for studying are facing this problem often. I guess this is something Docker tutorial/beginners guides don’t cover good enough.

Advertisements

About krzysztoftomaszewski

I've got M.Sc. in software engineering. I graduated in 2005 at Institute of Computer Science, Warsaw University of Technology, Faculty of Electronics and Information Technology. I'm working on computer software design and engineering continuously since 2004.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

One Response to Network problem inside a Docker container

  1. ddz says:

    dorzuc jeszcze artykul z najczesciej wg Ciebie wykorzystywanymi komendami dockera

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s