Fix cannot access internet in your docker container

I use docker for testing environment. Somehow I found out that the docker container cannot access the internet and the solution is really simple:

$ sudo ifconfig docker0 down
$ sudo service docker restart
$ sudo ifconfig docker0 up

Or

$ sudo vim /etc/default/docker
DOCKER_OPTS="--dns 10.10.4.14 --dns 8.8.8.8 --dns 8.8.4.4"

Which:
10.10.4.14 in my localhost/laptop

Setup docker + jenkins + nginx

Let’s setup jenkins with docker with local url : jenkins.local

First, add local url to /etc/hosts

$ sudo echo -e "127.0.0.1\tjenkins.local" >> /etc/hosts

Install docker and pull newest jenkins image

$ sudo apt-get install docker.io
$ sudo docker pull jenkins
$ sudo docker run -itd --name jenkins --publish 8080:8080 --publish 50000:50000 jenkins

Setup nginx

$ sudo vim /etc/nginx/conf.d/jenkins.conf

nginx conf:

server {
  listen 80;
  server_name jenkins.local;
  charset utf-8;
  gzip_vary on;
  access_log /var/log/nginx/jenkins.access.log;
  error_log /var/log/nginx/jenkins.error.log;
  location / {
    proxy_pass http://127.0.0.1:8080;
  }
}

Save config and restart nginx

$ sudo service nginx restart

Open browser, and navigate to http://jenkins.local