Unable to go get dependency packages when building docker file [duplicate] - docker

I'm trying to do an jenkins on docker, on my machine (Ubuntu).
I have to access to the git repo, in my company.
But in jenkins, I get this error :
Could not resolve host: gogs.mycompany.com
I think this is an DNS error, so I tried to launch my docker like that (with --dns and --dns-search)
sudo docker run -p 8080:8080 -p 50000:50000 -v
/home/xero/jenkins:/var/jenkins_home
--name=myproject-jenkins2 --dns=127.0.1.1 --dns-search=mycompany.lan jenkins
Here my /etc/resolv.conf :
nameserver 127.0.1.1
search mycompany.lan
What I'm doing wrong ?

The DNS was wrong. (--dns=127.0.1.1)
This DNS server, is an internal DNS, Dnsmasq, it's a DNS forwarder.
So I needed to know the real internal DNS server :
nmcli dev show | grep DNS
And add the right address (10.0.1.1 in my case) :
sudo docker run -p 8080:8080 -p 50000:50000 -v
/home/xero/jenkins:/var/jenkins_home --name=myproject-jenkins2
--dns=10.0.1.1 jenkins

Related

how to ssh to docker container created from one machine (centos) from another machine(centos or mac)

I want to create a docker container from one machine (suppose having centos) machine and then access that container from another machine(may be centos or mac). How can we do that? Is it possible with macvlan networking? If yes , what are steps? If not, what is the way?
Depends from what is your final goal. Following are some approaches (depending on what you want to achieve as final goal):
Manage container and execute bash in the container on a remote host:
Easiest way is to use the environment variable DOCKER_HOST
export DOCKER_HOST=ssh://vagrant#192.168.5.178
docker exec -ti centos_remote /bin/bash
You can find more information in this answer https://stackoverflow.com/a/51897942/2816703
Use the container as a form of virtual machine on which user can ssh:
First you will need a container that is running the sshd. You will expose the port 22 on another port on the host network. Finally you will use the ssh with -p to connect that port. Here is a working example:
$ sudo docker run -d -P --name test_sshd rastasheep/ubuntu-sshd:14.04
$ sudo docker port test_sshd 22
0.0.0.0:49154
$ ssh root#localhost -p 49154
# The password is `root`
root#test_sshd $
or if you are on a remote machine, use the host IP address xxx.xxx.xxx.xxx, to connect to the container use:
$ ssh root#xxx.xxx.xxx.xxx -p 49154
# The password is `root`
Also you can pre-select a port (in this case port 22000) and test from the host.
~# docker run -d -p 22000:22 --name test_sshd rastasheep/ubuntu-sshd:14.04
~# ssh root#<ipaddress> -p 22000
Setup a network layer (L2/L3) between the hosts:
Using macvlan is one approach. Another approach is the ipvlan. In both cases, you are converting the host network adapter to a virtual router, after which you need to setup the routes. You can find detailed explanation on this link http://networkstatic.net/configuring-macvlan-ipvlan-linux-networking/

facing problem while Connecting python script with mysql metastore in cloudera quickstart docker image

Desciption: I am trying to connect my sql metastore of hive from python script on local machine.I am using docker image of cloudera quickstart to hadoop package.I am even exposing the my sql port(9083) while running the cloudera container but still it is not working.Am I exposing the port correctly or I need to do something else too
I am running the cloudera container using below command
docker run --hostname=quickstart.cloudera --privileged=true --publish-all=true --expose 9083 -t -i -p 8888:8888 -p 80:80 -p 7180:7180 -p 9083:9083 cloudera/quickstart /usr/bin/docker-quickstart
I am trying below python command to connect to the mysql db of cloudera docker image
db = pymysql.connect(host="127.0.0.1",
port="9083",# your host, usually localhost
user="hive", # your username
passwd="cloudera",
db="metastore"
) # name of the data base
Getting below error
Operational Error: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Win Error 10061] No connection could be made because the target machine actively refused it)")
Expected Result:
Python script should get connected to the mysql metastore db of hive
You have to specify the Host IP address in MySQL string connection if you are trying to connect to external MySQL. Here 127.0.0.1 point to localhost of the container, not the HOST.
Change your docker command and set the HOST IP in the container.
docker run --add-host hostdb:HOST_IP --hostname=quickstart.cloudera --privileged=true --publish-all=true --expose 9083 -t -i -p 8888:8888 -p 80:80 -p 7180:7180 -p 9083:9083 cloudera/quickstart /usr/bin/docker-quickstart
Now update the MySQL connection string and set the host to hostdb
db = pymysql.connect(host="hostdb", # this will point to IP that we set in docker run command
port="9083",# your host, usually localhost
user="hive", # your username
passwd="cloudera",
db="metastore"
)
Managing /etc/hosts
Your container will have lines in /etc/hosts which define the hostname
of the container itself as well as localhost and a few other common
things. The --add-host flag can be used to add additional lines to
/etc/hosts.
docker run reference

How to find the address at which Docker container is available in windows?

Using docker toolbox on windows 7
There are two images:
pg - dB(Postgre);
app - debian with django application, the image of which is built from
dockerFile - at the end of which the dev server is started
CMD ["python","./vfnd/manage.py","runserver", "0.0.0.0:8001"])
Create/start the container as follows
docker run -d --name pg_1 pg
docker run -d -p 8001:8001 --link pg_1 --name app_1 app
I check through 'ps' - containers are started:
app_1 PORT 0.0.0.0:8001->8001;
pg_1 PORT 5432
If you do run app_1 flag-it is visible print - the django dev server is running on 0.0.0.0:8001
On linux django application will be available at 127.0.0.1:8001
But on windows with localhost, the situation is different and it is recommended to run a command that will return the container address
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" app_1
But it returns "no value".
Docker inspect outputs the following:
Docker inspect outputs
Tried to pass on 172.17.0.3:8001(from Networks -> IP Address) but the page is not found.
What am I doing wrong? How do I know which address the container is available at?
You can find Docker Toolbox IP address like this :
open a terminal.
run this command : eval "$(docker-machine env default)"
run this command : docker-machine ip default

No such image or container error

I want to setup a rancher server and a rancher agent on the same server.
Here is what i have done for creating server:
docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
Then, I have opened my web-browser on 8080 port.
I have chosen a login/password and enabled access control.
Then i wanted to create a host (agent). Rancher web interface says me to type this command:
docker run -e CATTLE_AGENT_IP=x.x.x.x --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.10 http://nsxxx.ovh.net:8080/v1/scripts/yyyy:1514678400000:zzzz
I have no error message, but I do not see any entry in host section (in rancher web interface).
So I tried to execute a shell on the agent docker container:
docker exec -ti xxxxx /bin/bash
I tried to manually run run.sh script and here is what I see:
Error: No such image or container: nsxxx
I suppose this is because docker containers cannot communicate together, but I have done exactly what is in the documentation...
Thanks for your help
For docker exec your need to replace the xxxxx string with the container id or the name of the container. Both you get from the docker ps command

Make container accessible only from localhost

I have Docker engine installed on Debian Jessie and I am running there container with nginx in it. My "run" command looks like this:
docker run -p 1234:80 -d -v /var/www/:/usr/share/nginx/html nginx:1.9
It works fine, problem is that now content of this container is accessible via http://{server_ip}:1234. I want to run multiple containers (domains) on this server so I want to setup reverse proxies for them.
How can I make sure that container will be only accessible via reverse proxy and not directly from IP:port? Eg.:
http://{server_ip}:1234 # not found, connection refused, etc...
http://localhost:1234 # works fine
//EDIT: Just to be clear - I am not asking how to setup reverse proxy, but how to run Docker container to be accessible only from localhost.
Specify the required host IP in the port mapping
docker run -p 127.0.0.1:1234:80 -d -v /var/www/:/usr/share/nginx/html nginx:1.9
If you are doing a reverse proxy, you might want to put them all on a user defined network along with your reverse proxy, then everything is in a container and accessible on their internal network.
docker network create net
docker run -d --net=web -v /var/www/:/usr/share/nginx/html nginx:1.9
docker run -d -p 80:80 --net=web haproxy
Well, solution is pretty simple, you just have to specify 127.0.0.1 when mapping port:
docker run -p 127.0.0.1:1234:80 -d -v /var/www/:/usr/share/nginx/html nginx:1.9

Resources