1

I am new to Docker and experimenting by creating an image from an existing Rails/Unicorn/MySQL app. My files are below and the image successfully creates but I'm unclear if things are actually working properly as I can't access the traditional Unicorn localhost URL, or the boot2docker IP.

So my question is, how do I access a Unicorn server locally on OSX with a Docker image running?

Dockerfile

# Dockerfile
FROM seapy/rails-nginx-unicorn

# Publish port 8080
EXPOSE 8080

CMD ["bundle", "exec","unicorn", "-p", "8080"]

Docker Image Run Command

docker run --name games-app --link test-mysql:mysql -p 8080 -d -e SECRET_KEY_BASE=test sample_rails_games_app

Docker PS Output

docker ps
CONTAINER ID        IMAGE                    COMMAND                CREATED             STATUS              PORTS                     NAMES
cf9c45d62763        sample_rails_games_app   "bundle exec unicorn   17 minutes ago      Up 17 minutes       0.0.0.0:32777->8080/tcp   games-app
93485cb7bcca        mysql                    "/entrypoint.sh mysq   6 hours ago         Up 6 hours          3306/tcp                  test-mysql

If I try to hit localhost:8080 or http://192.168.59.103:8080/ I am getting a Gateway Timeout: can't connect to remote host

Docker Logs Output

docker logs cf9c45d62763
I, [2015-07-30T22:44:44.941674 #1]  INFO -- : listening on addr=0.0.0.0:8080 fd=9
I, [2015-07-30T22:44:44.941927 #1]  INFO -- : worker=0 spawning...
I, [2015-07-30T22:44:44.944000 #1]  INFO -- : master process ready
I, [2015-07-30T22:44:44.944836 #8]  INFO -- : worker=0 spawned pid=8
I, [2015-07-30T22:44:44.945103 #8]  INFO -- : Refreshing Gem list
I, [2015-07-30T22:44:46.729708 #8]  INFO -- : worker=0 ready

I have also tried the boot2docker workarounds from here to no avail: https://github.com/boot2docker/boot2docker/blob/master/doc/WORKAROUNDS.md

Any guidance is greatly appreciated.

1

1 Answer 1

1

You have to use the eth1 address of your boot2docker vm.

Run from a shell:

boot2docker ssh

and then

ifconfig eth1
docker@boot2docker:~$ ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 08:00:27:69:53:F6
          inet addr:192.168.59.103  Bcast:192.168.59.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe69:53f6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:170143 errors:0 dropped:0 overruns:0 frame:0
          TX packets:98176 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:107722766 (102.7 MiB)  TX bytes:13713741 (13.0 MiB)

docker@boot2docker:~$

192.168.59.103 is the address you want to use from your mac. The port depends on what port your are forwarding. For example in this case:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS              PORTS                   NAMES
2e1d63d6928a        f6ac7e4116f3        "/usr/sbin/sshd -D -   3 hours ago         Up About an hour    0.0.0.0:32771->22/tcp   mad_jones
104f730aa7da        f6ac7e4116f3        "/usr/sbin/sshd -D -   3 hours ago         Up About an hour    0.0.0.0:32770->22/tcp   reverent_almeida

it's either 32771 or 32770. In this example it's an sshd server running by in your case it would be your unicorn which would be port 32777 So I think you are connecting to the right address but you need to connect to 32777 instead.

Hope it helps.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks @Rico. This is helpful and I went down this path as well. If I hit http://192.168.59.103:32777/ I am getting some formatted We're sorry, but something went wrong. page that I assume is from Nginx. Upon inspecting the the production.log in the app, I see Mysql2::Error (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'. The MySQL container is running but this is where I'm reaching the edge of my knowledge. I've been trying to connect to the MySQL container and confirm my config but even connecting through command line gives me the can't connect.
So now that I know the containers are up, how do I connect all of this together?
@smugcloud that's a different question :-) Do you have a your mysql server running on a different container?
yeah, I debated starting another question ;-) MySQL is running in a container, Rails app is running in another, and I started the rails app with the linking command from above: docker run --name games-app --link test-mysql:mysql -p 8080 -d -e SECRET_KEY_BASE=test sample_rails_games_app
@smugcloud I can probably guess is that your rails app is not configured correctly to talk to the db, but that's more of question about linking the containers. :-) This is more of a specific question/answer forum rather than a troubleshooting back and forth forum. Can you ask that in a different question?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.