1

Hi can any one help me to tell the correct command to provide internet access to a running container ?

I know we have to specify --net in docker run command to access internet from inside container.

What if I want to provide internet access to container which I didn't ran with --net command (i.e to container which does not have internet access)

I got docker network connect NetworkName ContainerName/ID command from: https://docs.docker.com/engine/reference/commandline/network_connect/

but running above command does not providing internet access so requesting to share me correct command.

Note: Am trying this on centos container

d0bry
  • 2,232
  • 9
  • 16
sudhir tataraju
  • 1,159
  • 1
  • 14
  • 30
  • In which direction? You don't need to specify any special `--net` to make outbound connections. You don't for inbound connections either, but you do need a `-p` option to publish a port on the host. Also, I'd recommend against using a bare `centos` container for anything except the `FROM` line of a Dockerfile; if you're doing significant work you're best off writing a custom Dockerfile for it. – David Maze Aug 07 '18 at 21:09
  • I know use of -p option i.e if I don't pass -p then container able to read open ports of host and vice-versa. Please give me command to achieve my need mentioned in my question , I don't understand theory much. – sudhir tataraju Aug 08 '18 at 04:43

2 Answers2

1

Your docker containers should have internet access by default as that is the normal setup of docker, and by no means should they require providing --net to get that. If they don't then you probably have something mixed up on your host like ie. additional firewall rules or lack of ip forwarding enabled.

For starters, check if you have enabled ip forwarding, should look like following :

$ cat /proc/sys/net/ipv4/ip_forward
1

and verify if you don't have something funky in your iptables

Radek 'Goblin' Pieczonka
  • 21,554
  • 7
  • 52
  • 48
  • I didnt mixed up on my host like ie. additional firewall rules or lack of ip forwarding enabled. and inside my docker its not [root@rbtstaging ~]# docker run --rm -it centos:6.6 bash [root@bed723a72f5a /]# [root@bed723a72f5a /]# cat /proc/sys/net/ipv4/ip_forward 1 <--------------- If I give --net only am getting internet access so I raised question that what if I forget to mention --net and in such case to a running container how to provide internet access – sudhir tataraju Aug 08 '18 at 12:16
0

Docker containers should resolve internet traffic once you configured properly. Please check the container network status by,

Enter public DNS (8.8.8.8)manually in /etc/resolve.conf.

If not working check the container network side.

#goto /etc/default/docker
#add public DNS values there (DOCKER_OPTS="--dns 208.67.222.222 --dns 208.67.220.220")
#sudo service docker restart

Login to the container and ping google.com

Hareesh R
  • 509
  • 4
  • 3