Docker run asp.net core image - docker

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

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

Unable to load swagger api using docker container

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

How to pull and run a docker image from a repo - Docker

I have a WebApi created using .Net Core. I have a .dockerfile in the root of my solution:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["Nuget.config", ""]
COPY ["Proyecto.WebApi/Proyecto.WebApi.csproj", "Proyecto.WebApi/"]
COPY ["Proyecto.Model/Proyecto.Model.csproj", "Proyecto.Model/"]
COPY ["Proyecto.Bl/Proyecto.Bl.csproj", "Proyecto.Bl/"]
RUN dotnet restore "Proyecto.WebApi/Proyecto.WebApi.csproj" --configfile "Nuget.config"
COPY . .
WORKDIR "/src/Proyecto.WebApi"
RUN dotnet build "Proyecto.WebApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Proyecto.WebApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Proyecto.WebApi.dll"]
I can build, run and push my Api without problem using those commands:
docker build -t dockerlocal .
docker run -d -p 8080:80 --name myapp dockerlocal
docker tag <image_id> docker.nexus.example.com/dockerlocal
docker push docker.nexus.example.com/dockerlocal
When I test my api from the browser http://localhost:8080/api/values, it works perfectly.
Now I need, download the image from the repo and run the Api, so I execute:
docker pull docker.nexus.example.com/dockerlocal
docker run -d -p 9090:90 --name mynexusapp docker.nexus.example.com/dockerlocal
According the console, everything is working. But when I test the API http://localhost:9090/api/values I get in my browser:
"localhost no envió ningún dato. ERR_EMPTY_RESPONSE"
What is the problem? Why I can't run my WebApi after docker pull comand.
Following discussion in the comments: the issue here was that the port mapping was changed from 8080:80 in the first command to 9090:90 in the second command. Switching mapping back to port 80 for container port fixes the issue as confirmed by the author.
Now, to explain what happens here: Port mapping 8080:80 means that you are mapping port 8080 on the host environment to port 80 on the guest environment. Where guest environment is the actual container.
Host port part of the mapping may be changed arbitrarily - i.e. changing it from 8080 to 9090 works - as long as the host port is not taken by another process. The same however is not true about the guest port, since the guest port is determined by the process that is run on the container. So if the container application listens to port 80, then switching guest mapping to port 90 (as happened in this case) won't work - because nothing is listening there.
It is also quite possible to have several port mapping, i.e. if in the container you have port 80 where your application listens and port 90 where some admin console listens, you may end up with 2 port mappings: say, 8080:80 and 9090:90.
If you want to use multiple environments at the same time - spawn multiple containers, i.e. you could do something like:
docker run -d -p 8080:80 --name myapp1 dockerlocal
docker run -d -p 9090:80 --name myapp2 dockerlocal
Note however, that you will end up with 2 separate containers running independent from each other.

Cannot access server running in container from host

I have a simple Dockerfile
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY . .
ENV GOPATH /app
RUN go install huru
EXPOSE 3000
ENTRYPOINT /app/bin/huru
I build like so:
docker build -t huru .
and run like so:
docker run -it -p 3000:3000 huru
for some reason when I go to localhost:3000 with the browser, I get
I have exposed servers running in containers to the host machine before so not sure what's going on.
From the information provided in the question if you see logs of the application
(docker logs <container_id>) than the docker application starts successfully and it looks like port exposure is done correctly.
In any case in order to see ports mappings when the container is up and running you can use:
docker ps
and check the "PORTS" section
If you see there something like 0.0.0.0:3000->3000/tcp
Then I can think about some firewall rules that prevent the application from being accessed...
Another possible reason (although probably you've checked this already) is that the application starts and finishes before you actually try to access it in the browser.
In this case, docker ps won't show the exited container, but docker ps -a will.
The last thing I can think of is that in the docker container itself the application doesn't really answer the port 3000 (I mean, maybe the startup script starts the web server on some other port, so exposing port 3000 doesn't really do anything useful).
In order to check this you can enter the docker container itself with something like docker exec -it <container_id> bash
and check for the opened ports with lsof -i or just wget localhost:3000 from within the container itelf
Try this one, if this has any output log. Please check them...
FROM golang:latest
RUN apt -y update
RUN mkdir -p /app
COPY . /app
RUN go install huru
WORKDIR /app
docker build -t huru:latest .
docker run -it -p 3000:3000 huru:latest bin/huru
Try this url: http://127.0.0.1:3000
I use the loopback

Run microsoft/nanoserver in a docker file

Link to microsoft/nanoserver
If I follow the process in the link above I can get docker nano-server to run inside of docker on the command line..
RUN --name nanoiis -d -it -p 8080:80 nanoserver/iis
is the commend line is use.
I want to put this into a docker file and build and image. So here is my dockerfile
FROM microsoft/nanoserver
# Set the working directory to /app
WORKDIR /app
# Copy the Public directory contents into the container at /app
ADD ./Public /app
# -p 8080:80 Map TCP port 80 in the container to port 8080 on the Docker host.
RUN --name nanoiis -d -it -p 8080:80 nanoserver/iis
I get an error
Error response from daemon: Dockerfile parse error line 12: Unknown
flag: name
My question is what am I doing wrong?
I am following the example on building a docker image here:
https://docs.docker.com/get-started/part2/
Next question is what is the command I would use to get my app running? In the example they use.
CMD ["python", "app.py"]
What should I use to get nano-server running?
Last point me to some documentation to get a web site running into the Nano-Server. It seems that Nano-Server has changed it role within Microsoft.

Resources