如何在Docker中使用新的jar文件创建映像? [英] How to create image with my new jar file in Docker?
问题描述
我是Docker的新手,需要将jar文件部署到Docker中.因此,我已经实现了"Hellow World"程序,并尝试如下创建容器,但是调用它时出现"curl: (56) Recv failure: Connection reset by peer
"错误.
I'm very new to docker and need to deploy jar file into docker. So I have implemented "Hellow World" program and trying to create container as follows but I'm getting "curl: (56) Recv failure: Connection reset by peer
" error while calling it.
请帮助我,我已经为此工作了4天.
Help me please I have been working on this for 4 days.
Dockerfile:
Dockerfile:
##### Version: 0.0.1
FROM ubuntu:14.04
MAINTAINER Siva "siva@example.com"
RUN apt-get update
#### installing JDK
RUN apt-get install -y openjdk-7-jdk
ADD dockertest.jar /usr/share/java/
EXPOSE 8089
构建命令:
sudo docker build -t="img33/img33" .
从图片中启动容器:
sudo docker run -it -p 80 --name imgcon33 img33/img33
供参考
docker@boot2docker:~/jardeploy$ sudo docker build -t="img33/img33" .
Successfully built f602b747548a
docker@boot2docker:~/jardeploy$ sudo docker run -it -p 80 --name imgcon33 img33/img33
root@21df09a79175:/# exit
docker@boot2docker:~/jardeploy$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21df09a79175 img33/img33:latest "/bin/bash" 14 seconds ago Exited (0) 9 seconds ago imgcon33
docker@boot2docker:~/jardeploy$ docker start 21df09a79175
21df09a79175
docker@boot2docker:~/jardeploy$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21df09a79175 img33/img33:latest "/bin/bash" 29 seconds ago Up 3 seconds 8080/tcp, 0.0.0.0:49231->80/tcp imgcon33
docker@boot2docker:~/jardeploy$ curl localhost:49231
curl: (56) Recv failure: Connection reset by peer
推荐答案
您未定义用于传入连接的端口,boot2docker将端口80映射到范围49153至65535中的第一个空闲的高范围端口(请参阅操作方法).在boot2docker中 和
You did not define port for incomming connections, and boot2docker maps port 80 to the first free high-range port in range 49153 to 65535 (see how to do it in boot2docker and docker).
这是对我有用的设置(尽管在Windows上,但对于OSX同样适用),我已将您的应用程序映射到端口8000,请随时进行更改:
Here is the setup that worked for me (on Windows, though, but the same thing is for OSX), I have mapped your application on port 8000, please feel free to change it:
c:\>boot2docker init
Virtual machine boot2docker-vm already exists
c:\>boot2docker up
Waiting for VM and Docker daemon to start...
..........ooo
Started.
Writing C:\Users\xyz\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\xyz\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\xyz\.boot2docker\certs\boot2docker-vm\key.pem
Docker client does not run on Windows for now. Please use
"boot2docker.exe" ssh
to SSH into the VM instead.
c:\>boot2docker ssh -L 0.0.0.0:8000:localhost:8000
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.3.2, build master : 495c19a - Mon Nov 24 20:40:58 UTC 2014
Docker version 1.3.2, build 39fa2fa
docker@boot2docker:~$ docker run -it -p 0.0.0.0:8000:80 --name imgcon33 img33/img33
此设置将您的应用程序映射如下: imgcon33(端口80)-> docker(8000)-> boot2docker(8000)-> localhost(8000)
This setup maps your application like this: imgcon33 (port 80) -> docker (8000) -> boot2docker (8000) -> localhost (8000)
如果您从boot2docker运行curl,那么一个简单的
If you run curl from boot2docker, then a simple
curl localhost:80
应该足够了. 但是,如果要从主机容器(托管boot2docker的容器)访问应用程序,则必须以以下方式运行它:
should be enough. But if you want to access your application from host container (the one that hosts boot2docker), you have to run it as
curl localhost:8000
这篇关于如何在Docker中使用新的jar文件创建映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!