Unable to load swagger api using docker container - docker

I am unable to load swagger api using Docker where as the jar file runs fine: java -jar abc.jar
My swagger api doc: http://localhost:8080/api-docs/swagger.json
Docker File
FROM openjdk:14.0.2
RUN mkdir /opt/app
COPY ./build/libs/OrderManagementSystem-1.0-SNAPSHOT.jar /opt/app
EXPOSE 8080
CMD ["java", "-jar", "/opt/app/OrderManagementSystem-1.0-SNAPSHOT.jar"]
Command
docker run -p 3333:8080 order-price
I am unable to load the page http://localhost:8080/swagger

it seems you are hitting the wrong URL.
it should be,
http://localhost:3333/swagger
or
http://localhost:3333/api-docs/swagger.json
when you are binding ports while running docker, it is docker run -p host-port:container-port

If you run your container like that:
docker run -p 3333:8080 order-price
You are telling docker to expose internal port 8080 to port 3333 on your host.
So if you wan't to access Swagger API, you have to use :
http://localhost:3333/swagger
If you really want to user port 8080 on your host, then you have to launch your container like that :
docker run -p 8080:8080 order-price

Related

How to properly expose/publish ports for a WebUI-based application in Docker?

I'm trying to port this webapp to Docker. I wrote the following Dockerfile:
FROM anapsix/alpine-java
MAINTAINER <name>
COPY aard2-web-0.7-java6.jar /home/aard2-web-0.7-java6.jar
COPY start.sh /home/start.sh
CMD ["bash", "/home/start.sh"]
EXPOSE 8013/tcp
Here are the contents of start.sh:
#!/bin/bash
java -Dslobber.browse=true -jar /home/aard2-web-0.7-java6.jar /home/dicts/*.slob
Then I built the image:
docker build -t aard2-docker .
And I used the following command to run the container:
docker run --name Aard2 -p 127.0.0.1:8013:8013 -v /home/<name>/dicts:/home/dicts aard2-docker
The app is running normally, prompting that it's listening at http://127.0.0.1:8013. However, I opened the address only to find that I couldn't connect to the app.
I tried using the EXPOSE command (as shown in the Dockerfile snippet above) and variants of the -p flag, such as -p 127.0.0.1:8013:8013, -p 8013:8013, -p 8013:8013/tcp, but none of them worked.
How can I expose/publish the port to 127.0.0.1 properly? Thanks!
Here's the response from the original author:
you need to tell the server to listen on all network interfaces instead of localhost - that is you are missing -Dslobber.host=0.0.0.0
this works for me:
FROM anapsix/alpine-java
COPY ./build/libs/aard2-web-0.7.jar /home/aard2-web-0.7.jar
CMD ["bash", "-c", "java -Dslobber.host=0.0.0.0 -jar /home/aard2-web-0.7.jar /dicts/*.slob"]
EXPOSE 8013/tcp
and then run like this:
docker run -v $HOME/Downloads:/dicts -p 8013:8013 --rm aard2-web
-Dslobber.browse=true opens default browser, I don't think this has any effect in docker so don't need that.
https://github.com/itkach/aard2-web/issues/12#issuecomment-895557949

docker container can't communicate to other container on the same network

I have two images that should communicate with each other. The first image is the web API, and the second image is the web itself.
Before I build and run the images, I create a new network called nat using the command:
docker network create nat
After this, I start to create my images which I called image-api that runs on port 8080 and image-web that run on port 8081.
Then, I run the image-api image using the command:
docker run -d -p 3000:8080 --network nat image-api
I mapped the container port 8080 to my host port 3000. I tried to access the localhost port 3000 in my browser and it's running without an error and giving me the response as it should be.
The problem here is, my second image, the image-web image. I try to run it using the command:
docker run -d -p 3001:8081 --network nat image-web
When I try to access localhost:3001 in my browser, it's running, but not giving the data from image-api container. When I try to logs the image-web container, it's giving me an error like:
Error: getaddrinfo ENOTFOUND image-api
Just in case, I try to access the image-api container from my image-web container using URL like this:
http://image-api/ping
Here's my image-api Dockerfile:
FROM node:14 as builder
WORKDIR /app
COPY package.json /app
RUN npm install
FROM node:14
EXPOSE 8080
CMD ["node", "server.js"]
WORKDIR /server
COPY --from=builder /app/node_modules /server/node_modules
COPY server.js .
And here's my image-web Dockerfile:
FROM node:14 as builder
WORKDIR /app
COPY package.json .
RUN npm install
FROM node:14
ENV IMAGE_URL=http://image-api/ping
EXPOSE 8081
CMD ["node", "app.js"]
WORKDIR /web
COPY --from=builder /app/node_modules /web/node_modules
COPY /src .
Just in case, I already tried to run both of them without docker, and they run as it should be in my local computer.
EDIT:
I've also tried to run the container using name like this:
docker run -d -p 3000:8080 --network nat --name imageapi image-api
And try to access it using:
http://imageapi/ping
But it's still giving me the same error
SOLUTIONS:
As being pointed out by #davidMaze on the answer. After running our container using --name tag. I can access my container using http://imageapi:8080/ping
You need to explicitly specify a docker run --name when you start the container. Since you can run multiple containers from the same image, Docker doesn't automatically assign a container name based on the image name; you need to set it yourself.
docker run -d -p 3000:8080 --network nat --name image-api image-api
docker run -d -p 3001:8081 --network nat --name image-web image-web
Once you set the container name, Docker provides an internal DNS service and the container will be reachable by that name from other containers on the same network.
Use bridge networks in the Docker documentation describes this further, though mostly in contrast to an obsolete networking mode.

Docker run asp.net core image

I have simple asp.net core app with /students endpoint thats return test data for me. I have following docker file
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
COPY bin/Release/netcoreapp3.1/publish/ App/
WORKDIR /App
EXPOSE 5000
ENTRYPOINT ["dotnet", "Node.dll", "--urls", "http://0.0.0.0:5000"]
Then, i run it using docker run node -p 5000:5000 and expect if I go for localhost:5000/students I get response but I'm not.
If I do something like docker exec -it container_name /bin/bash and then curl 0.0.0.0:5000/students I get response so I'm sure it's running. How can I use my app outside of container? I've tried other ports like 80 and 443 etc.
Well, the problem was you have to write docker run -p 5000:80 node to make it work as espected because docker didn't apply any -p args

Ngnix Docker not serving content

I'm trying to build a docker container out of an angular 4 application. When running it with
docker run -p 80:80 -v /Users/mles/Documents/devicelab/dist/devicelab:/usr/share/nginx/html:ro nginx
I can see the index.html in the browser with localhost:80.
To make it portable I've made a DOCKERFILE:
FROM nginx
COPY dist/devicelab /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
I'm building it with
docker build --no-cache --rm -t dockerregistry.test.com/devicelab/devicelab .
then running it with
docker run dockerregistry.test.com/devicelab/devicelab:latest
Now when I hit localhost:80 nothing is happening. Nothin shows up in the browser and there is no log on the console. What is wrong with my Dockerfile?
You forgot the port on docker run
docker run -p 80:80 dockerregistry.test.com/devicelab/devicelab:latest
#rafaelncarvalho was correct in regards to the -p param, but for clarification the -p is to publish the already exposed port to the outside the network. Without the -p nginx will be accessible if you exec -it bash in, but not outside. The -p aka --publish also allows gives you control for mapping the container port to what you choose. ex docker container run -p 8080:80 nginx will publish the nginx server on port 8080

docker exposing multiple ports - not working

I have a docker image that on running executes the following script
java -jar myjar.jar & disown
python2.7 manage.py runserver 0.0.0.0:9999
the myjar.jar program exposes a webservice and listens to port 11111.
In my Docker file i expose these 2 ports like so:
EXPOSE 9999 11111
This is how i run the image:
docker run --rm -p 9999:9999 -p 11111:11111 myimage
I can access the python web process with the url localhost:9999/admin/.
When i try to access the java web service with curl localhost:11111/myservice?wsdl I get connection refused.
When i enter the container with a terminal using
docker exec -i -t <container_id> bash
and run curl localhost:11111/myservice?wsdl i get the wsdl content.
Where is my port binding going wrong? (or port exposing? or maybe the way i am running the jar file?)

Resources