简体   繁体   English

在Mac OS X上将应用程序码头化

[英]dockerizing an application on Mac OS X

I installed boot2docker as explained on the docker website. 我按照docker网站上的说明安装了boot2docker。 Here are some command runs to show that I have things installed correctly: 这是一些命令运行,显示我已正确安装了东西:

$$:~ kv$ boot2docker start
Waiting for VM and Docker daemon to start...
...................ooo
Started.
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.

$$:~ kv$ docker images
REPOSITORY  TAG     IMAGE ID        CREATED             VIRTUAL SIZE
ubuntu     14.04   b39b81afc8ca        11 days ago         188.3 MB
hello-world  latest e45a5af57b00        3 weeks ago         910 B

After this, I ran the following command: 之后,我运行了以下命令:

docker run -t -i ubuntu:14.04 /bin/bash

Inside the container, I installed zeromq, and started a zeromq server on port 5555 using tcp. 在容器内部,我安装了zeromq,并使用tcp在端口5555上启动了zeromq服务器。

My questions are following: 我的问题如下:

  1. If I exit out of the container, will it save all the work I do inside it? 如果我退出容器,是否会将我所做的所有工作保存在其中?

  2. I have no idea how to connect to the server running on port 5555. I read something about exposing a port, but I am not sure how to go about doing that. 我不知道如何连接到端口5555上运行的服务器。我读了一些有关公开端口的内容,但是我不确定该怎么做。 I did an ifconfig inside the container, and tried to connect to the server from the host like this: 我在容器内做了一个ifconfig,并尝试从主机连接到服务器,如下所示:

     $$:~ kv$ ./zmq_client tcp://container_ip:5555 

    This did not work. 这没有用。 Can someone please lists the steps I need to take in order to connect to the server running within the container. 有人可以列出我要连接到容器中运行的服务器所需采取的步骤。

For completion sake, I am providing the list of my environment variables: 为了完整起见,我提供了我的环境变量列表:

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/km/5kbpdx4s7cg4rmyc6d5q9l9r0000gq/T/
DOCKER_HOST=tcp://192.168.109.103:2376
Apple_PubSub_Socket_Render=/tmp/launch-1tWMHJ/Render
TERM_PROGRAM_VERSION=326
OLDPWD=/Users
TERM_SESSION_ID=262CBC8B-0A74-4B70-9F28-D9FA51FF713C
USER=kv
SSH_AUTH_SOCK=/tmp/launch-ZTWNGL/Listeners
__CF_USER_TEXT_ENCODING=0x1F7:0:0
DOCKER_TLS_VERIFY=1
__CHECKFIX1436934=1
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
PWD=/Users/kv
DOCKER_CERT_PATH=/Users/kv/.boot2docker/certs/boot2docker-vm
HOME=/Users/kv
SHLVL=1
LOGNAME=kv
LC_CTYPE=UTF-8
DISPLAY=/tmp/launch-rco9zt/org.macosforge.xquartz:0
_=/usr/bin/env

One last question I have is about code performance. 我还有最后一个问题是关于代码性能。 So within my Mac OS X, I have a docker container running (which runs Ubuntu). 因此,在我的Mac OS X中,我有一个运行的docker容器(运行Ubuntu)。 If I run the application, like a zeromq based server inside the container, will it not be slower as compared to running it on Mac OS X directly. 如果我运行该应用程序,就像在容器内基于零mq的服务器那样,与直接在Mac OS X上运行相比,它不会慢。 Please explain the benefits of using docker in such a scenario.. 请说明在这种情况下使用docker的好处。

You should really do some more reading and research before turning to SO, then ask about anything you can't figure out. 在转向SO之前,您确实应该做更多的阅读和研究,然后询问您无法解决的问题。 But: 但:

  1. No. If the container is "exited" you can restart it and your files will still be there, but once it is removed your files are gone. 否。如果容器已“退出”,则可以重新启动它,并且文件仍将保留在其中,但是一旦将其删除,则文件将消失。 You can use docker commit to save them to an image, but the best bet is to use a Dockerfile. 您可以使用docker commit将它们保存到映像,但是最好的选择是使用Dockerfile。

  2. docker run -p 5000:8000 image will expose port 8000 in the container as port 5000 on the host. docker run -p 5000:8000 image会将容器中的端口8000公开为主机上的端口5000。

  3. Yes, it will be slower due to the boot2docker VM. 是的,由于使用了boot2docker VM,它将变慢。 It would not be slower if you were running on a Linux host. 如果您在Linux主机上运行,​​速度不会降低。 The advantage is that zeromq is now running in an isolated container with all its dependencies. 优势在于,zeromq现在正在具有所有依赖性的隔离容器中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM