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
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
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
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.