I have a Node.js service built with Restify and I'm trying to use Docker to wrap it all up. My Dockerfile seems to work fine and my DB and Service boots and using docker exec
I can curl
REST endpoints just fine. However, the ports don't seem to get exposed. I'm on a Mac if that matters. Here's my Dockerfile:
FROM ubuntu:14.04
MAINTAINER Oscar Godson
RUN apt-get update
RUN apt-get install -y nodejs-legacy
RUN apt-get install -y npm
RUN apt-get install -y mysql-server
RUN apt-get install -y mysql-client
COPY . /src
WORKDIR /src
RUN cd /src;npm install
EXPOSE 4000
CMD ./bin/installer.sh
Here's installer.sh:
service mysql start
mysql -u root < ./bin/demo-data.sql
node index.js
Note: The MySQL DB is purely for testing and local dev. We use AWS RDS for production so thats why its using root access.
Now if I do:
docker run -p 4000:4000 86d57dae4522
And then:
curl http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD
I get:
curl: (7) Failed to connect to localhost port 4000: Connection refused
If I do it within the container with exec like:
docker exec -i 86d57dae4522 curl http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD
I get (this is expected since I havent logged into my service):
{"message":"You don't have permissions to do that"}
Within my Restify server I did 0.0.0.0
for the host too since I saw some comments about Rails apps needing to set that so I thought I'd try it in Node/Restify but no luck.:
server.listen(process.env.PORT || 4000, "0.0.0.0", function() {
console.log('%s listening at %s', server.name, server.url);
});
I've also tried a friend suggestion of:
docker run --net="host" 7500cdb
And i read that --hostname
puts the IP you pass it into the /etc/hosts
so I tried (this is my computers IP)
docker run --hostname="192.168.2.6" 7500cdb
No luck with any of these. Any ideas?
Yes, it matters very much that you're on a Mac.
Docker doesn't run natively on the Mac, so you're running boot2docker which is setting up a little VirtualBox-based VM. It is that VM that's running Docker. When you forward some host ports, you are forwarding ports on the VM to the container. When you mount a local path on a container, it's a local path on the VM.
In your example, rather than
http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD
you need to run
http://$(boot2docker ip):4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD
You can also run boot2docker ip
and save that address in your /etc/hosts
file under a friendly name, if you like. (This can be helpful if your container is going to serve SSL certs).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments