来自现有Rails / Unicorn / MySQL应用程序的Docker映像 [英] Docker image from existing Rails/Unicorn/MySQL app

查看:186
本文介绍了来自现有Rails / Unicorn / MySQL应用程序的Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,并通过从现有的Rails / Unicorn / MySQL应用程序创建一个图像进行实验。我的文件在下面,图像成功创建,但是我不清楚事情是否正常工作,因为我无法访问传统的Unicorn本地主机URL或boot2docker IP。



所以我的问题是,如何在运行Docker映像的OSX上本地访问Unicorn服务器?



Dockerfile

 #Dockerfile 
FROM seapy / rails-nginx-unicorn

#发布端口8080
EXPOSE 8080

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

Docker图像运行命令



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



Docker PS输出

  docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf9c45d6 2763 sample_rails_games_appbundle exec unicorn 17分钟前上传17分钟0.0.0.0:32777->8080/tcp games-app
93485cb7bcca mysql/entrypoint.sh mysq 6小时前Up 6小时3306 / tcp test-mysql

如果我尝试点击 localhost:8080 http://192.168.59.103:8080/ 我收到一个网关超时:无法连接到远程主机



Docker Logs输出

  docker logs cf9c45d62763 
I,[2015-07-30T22:44:44.941674#1] INFO - :listen on addr = 0.0.0.0:8080 fd = 9
I,[2015-07-30T22 :44:44.941927#1] INFO - :worker = 0产卵...
I,[2015-07-30T22:44:44.944000#1]信息 - :主流程准备
I, [2015-07-30T22:44:44.944836#8] INFO - :worker = 0 spawned pid = 8
I,[2015-07-30T22:44:44.945103#8] INFO - :刷新宝石列表
I,[2015-07-30T22:44:46.72 9708#8] INFO - :worker = 0 ready

我也从这里尝试过boot2docker解决方法无效: https://github.com/boot2docker/boot2docker/blob /master/doc/WORKAROUNDS.md



非常感谢任何指导。

解决方案

您必须使用boot2docker vm的eth1地址。



从shell运行:

  boot2docker ssh 

然后

  ifconfig eth1 
docker @ boot2docker:〜$ ifconfig eth1
eth1链接封装:以太网HWaddr 08:00:27 :69:53:F6
inet addr:192.168.59.103播放:192.168.59.255掩码:255.255.255.0
inet6 addr:fe80 :: a00:27ff:fe69:53f6 / 64范围:链接
UP BROADCAST RUNNING MULTICAST MTU:1500公制:1
RX包:170143错误:0丢失:0超支:0帧:0
发送数据包:98176错误:0丢弃:0超支:0载体:0
碰撞:0 txqueuelen:1000
RX字节:107722766(102.7 MiB )TX字节:13713741(13.0 MiB)

docker @ boot2docker:〜$

192.168.59.103 是您要从Mac使用的地址。端口取决于您正在转发的端口。例如在这种情况下:

  $ docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e1d63d6928a f6ac7e4116f3/ usr / sbin / sshd -D - 3小时前Up大约一个小时0.0.0.0:32771->22/tcp mad_jones
104f730aa7da f6ac7e4116f3/ usr / sbin / sshd -D - 3小时前Up大约一小时0.0.0.0:32770->22/tcp reverent_almeida

它是 32771 32770 。在这个例子中,这是一个sshd服务器在你的情况下运行,这将是你的独角兽,它将是端口 32777 所以我认为你正在连接到正确的地址,但是你需要连接至 32777



希望有帮助。


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.

解决方案

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.

这篇关于来自现有Rails / Unicorn / MySQL应用程序的Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆