How do I expose port from Container to host? - docker

so I have my project which when installed on host makes login page available (via embedded Tomcat server) as
https://127.0.0.1:8443/
Now I installed this in ubuntu container and for installation the command I used was
docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8080:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash
When I did that, I was not able to reach this on my host browser, what I tried was
https://my-docker-machine-ip:8443/ # I am using Mac OSX
Next, I thought to provide exact mapping and I tried
docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 192.168.99.100:8443:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash
and tried the same URL again, but no luck
What I see is HTTP 404 from Apache. What am I missing?
However within the container, I see log that tells me that server is running
11 May 2016 22:19:19,166 [INFO ] [main] EmbeddedWebServer | Starting tomcat server on port 8443 ...

The syntax is -p hostPort:ContainerPort. Your first example had the right syntax but the 'wrong' port (compared to what you were expecting).
Instead of:
docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8080:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash
Use:
docker run -it --name lp --dns=122.17.213.214 --dns=122.26.00.10 --dns-search=corp.sfc.san -p 8443:8443 -v ~/Downloads/logs:/logs -v ~/Downloads:/installers ubuntu /bin/bash
Then
https://my-docker-machine-ip:8443/ # I am using Mac OSX
should work.

Related

Docker, unable to run Ghost on default port 2368

Using Official (Docker) image from docker hub:
I was expecting this to work on the default port 2368
but localhost:2368 just hung
docker run -d --name some-ghost2 -v some-ghost-data:/var/lib/ghost/content ghost
localhost:3001 worked
docker run -d --name some-ghost2 -v -p 3001:2368 some-ghost-data:/var/lib/ghost/content ghost
Then the links in the introduction pages failed as they linked to 2368
The fix, which took me a while to get to:
docker run -d --name some-ghost2 -v -p 2368:2368 some-ghost-data:/var/lib/ghost/content ghost

In Docker, bind mounting the nscd socket breaks gethostbyname

I have a dockerized application that requires the nscd socket from the docker host. So I bind mount the socket at run time. DNS, getpwnam, getpwuid, etc. all work fine. Strangely though, I have found that gethostbyname doesn't work anymore. For example:
docker run --rm -v /var/run/nscd/socket:/var/run/nscd/socket ubuntu hostname -i
hostname: Name or service not known
However, under alpine, it does work:
docker run --rm -v /var/run/nscd/socket:/var/run/nscd/socket alpine hostname -i
172.18.85.4
Does anyone know why this breaksgethostbyname and how to fix it?
Update: if I use the same glibc on the host and container, it still breaks:
ldd --version
ldd (GNU libc) 2.17
docker run --rm centos ldd --version
ldd (GNU libc) 2.17
docker run --rm -v /var/run/nscd/socket:/var/run/nscd/socket centos hostname -i
hostname: Name or service not known
Setting the LOCALDOMAIN to nothing works:
docker run -it --rm -v /var/run/nscd/socket:/var/run/nscd/socket --env LOCALDOMAIN='' centos hostname -i

Docker ignores local project

I'm trying to run a local project folder with apache, seems to default to the server message of "It works" instead of running my project folder. When I go to 127.0.0.1:8080
sudo docker run -d -p 8080:80 -v "$PWD:/home/me/public_html/project-folder" httpd
I'm using ubuntu desktop
you need to mount the location of your project to this directory in the container: /usr/local/apache2/htdocs/
try this:
sudo docker run -d -p 8080:80 -v "/home/me/public_html/project-folder:/usr/local/apache2/htdocs" httpd
this is explained here: https://hub.docker.com/_/httpd/

Virtualbox inside Docker

I'm trying to get VirtualBox to run inside of Docker. I'm using this: https://registry.hub.docker.com/u/jess/virtualbox/dockerfile/.
When I run the command:
sudo docker run -d \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--privileged \
--name virtualbox \
jess/virtualbox
It adds virtualbox inside a container. When I run sudo docker start container_id, it echoes back the container_id but doesn't add it to the running containers. I check with sudo docker ps and it is not there; however, it is there with sudo docker ps -a.
What am I doing wrong? I get no errors either.
EDIT: I'm running Docker in Ubuntu 15.04 (Not inside VirtualBox)
You have to let docker to connect to your local X server. There are different ways to do this. One straight way is running xhost +local:docker before running your container (i.e.: before docker run).

Docker port rewrite

I used docker for wordpress like this:
Create volume containers:
$ docker create -v /home/juanda/project/bbdd:/var/lib/mysql --name bbdd ubuntu /bin/true
$ docker create -v /home/juanda/project/web:/var/www/html --name web ubuntu /bin/true
Mysql container:
$ docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql
Apache, php and wordpress container:
$ docker run --volumes-from web --name apache --link mysql:mysql -d -p 5555:80 wordpress
I installed and ran everything ok. If I remove apache container (stop and rm) and I launch it awain in another port (8080 instead of 5555), it rewrites url in navigator to 5555 and I get a connection error. Any idea?

Resources