How to create image with my new jar file in Docker?

旧城冷巷雨未停 提交于 2019-12-08 03:58:06

问题


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.

Help me please I have been working on this for 4 days.

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

Build command:

sudo docker build -t="img33/img33" .

Launching the container from image:

sudo docker run -it -p 80 --name imgcon33 img33/img33

For reference

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

回答1:


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).

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

This setup maps your application like this: imgcon33 (port 80) -> docker (8000) -> boot2docker (8000) -> localhost (8000)

If you run curl from boot2docker, then a simple

curl localhost:80

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


来源:https://stackoverflow.com/questions/27124897/how-to-create-image-with-my-new-jar-file-in-docker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!