Azure App Service Container HealthCheck - small - docker

I have a Azure App Service Container failing on the healthcheck.
My docker is a very light Alpine, but I do have netcat
The app service fails because port 80 is not responding on the container. The container is not a web server.
My Dockerfile: (there is no service to return on port 80 in this container )
EXPOSE 80
HEALTHCHECK --interval=5m --timeout=3s CMD curl -f http://localhost/ || exit 1
What can I put in the dockerfile to be the healthcheck ?
How do I write the Dockerfile ?

Related

expose container port in user define bridge network

I am creating a nginx container from dockerfile as shown below.
I have performed following sequence of steps.
Dockerfile content
FROM nginx
COPY . /usr/share/nginx/html
EXPOSE 80
Build docker image from Dockerfile
docker build -t mynginx
create user defined "bridge" network "my-bridge"
docker network create my-bridge
create nginx container in "my-bridge" network and exposed port 80 of nginx to
8084 port of host
docker run -itd --network my-bridge --name mynginxcontainer -p 8084:80 mynginx /bin/bash
when i try to access container using host port then nginx is not accesible
http://Public_IP_OF_EC2:8084
So the question is why am I not able to access nginx using host's port?
All steps looks good except docker run
you are providing /bin/bash as entrypoint which overwrites existing CMD for nginx.
Kindly start without /bin/bash should be working or provide valid entrypoint which start nginx service inside container.

The server doesn't respond anymore after I switch framework Gin to Echo

I used to use Gin(Golang framework) and deploy docker image to GKE.
It was working totally fine.
But the server doesn't respond anymore when I switched Gin to Echo(it is also Golang framework)
I think it is because there is something wrong with port combination(port forwarding).
My echo server code is like below.
func main() {
e := presentation.Router()
e.Logger.Fatal(e.Start(":8080")) // listen and serve on :8080
}
and my dockerfile is like below.
FROM alpine:3.9
WORKDIR /app
ADD main /app
ENV PORT 80
EXPOSE 80
CMD ["./main"]
When request reaches to 80 port, it has to render to 8080 port (container port).
But it doesn't seem that it is working like above at the moment.
How can I match outer port and inner port??
Use the command docker run -p 80:8080 image_name for running the container, it will publish the port 8080 of the container and map it with port 80 of the host.

Unable to run application on Docker if used any other port except default port 80

I have a demo app which is hosted on docker. The exposed port for Docker is 80 and the app is running fine on local machine and I am able to see landing page for my app on localhost:8888.
Docker file is as given below
FROM microsoft/aspnetcore:2.0
COPY dist /app
WORKDIR /app
EXPOSE 80/tcp
ENTRYPOINT ["dotnet", "demoapp.dll"]
Whenever I change line "EXPOSE 80/tcp" to for ex- "EXPOSE 8080/tcp" , "EXPOSE 5000/tcp" etc to expose any other port except 80 of Docker container as given in many online available sample codes, I am unable to run my app on browser. Any port except 80 is not working.
I am able to create image and create container for application too. Everything goes well but when I try to run app on browser (localhost:8080/5000/9000 etc.) The app landing page doesn't load.
Any suggestions? Do I need to do some port related configuration or contact my network team? or any code which I am missing here?
You should be able to expose any port inside the container.
However you publish the exposed port on the host during the start of the container.
This is done with the -p flag of the docker run command.
When you say you are able to access the application using localhost:8888 it means you have run the docker run command with -p 8888:80. This publishes the container port 80 onto the host as port 8888.
To use any other port just change the docker run command to -p 8888:<new exposed port> and that should do it.
See the docker run command help for more info:
https://docs.docker.com/v17.12/edge/engine/reference/commandline/run/#publish-or-expose-port--p-expose
Publish or expose port (-p, –expose)
$ docker run -p 127.0.0.1:80:8080 ubuntu bash
This binds port 8080 of the container to port 80 on
127.0.0.1 of the host machine. The Docker User Guide explains in detail how to manipulate ports in Docker.
If your application runs at port suppose 8080 then make sure to do port mapping while running the container.
docker run -itd -p 8080:8080 <image>
This will map port 8080 of host on port 8080 inside the container. (-p hostport:containerport)
If you don't want port mapping then run docker container in host mode.
docker run -itd --net=host <image>
In this case your container use host network, so whatever port your application is running inside it should get exposed.
For microsoft/aspnetcore, it sets the ASPNETCORE_URLS environment variable to http://+:80 which means that if you have not explicity set a URL in your application, via app.UseUrl in your Program.cs for example, then your application will be listening on port 80 inside the container.
Reference: microsoft/aspnetcore
If you want to change the default port 80, you need to use UseUrls in Program.cs with like below, and use EXPOSE 8080/tcp in dockerfile.
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://+:8080")
.UseStartup<Startup>();
Or, you need to change ASPNETCORE_URLS environment like
FROM microsoft/aspnetcore:2.0
COPY dist /app
WORKDIR /app
EXPOSE 8080/tcp
ENV ASPNETCORE_URLS=http://+:8080
ENTRYPOINT ["dotnet", "demoapp.dll"]
Command to run
docker run -it -p 8080:8080 mytest

Container should communicate to host network, but does not

I have a two HTTP servers on my host machine; one listening on 8080, the other listening on 8081. The 8080 is a webapp, and the 8081 is an API.
I also have a Docker container that should connect to the webapp on 8080 using an automated tool, and that webapp should make HTTP requests to the API that's on 8081.
Here is a visual representation of what I want:
Host machine HTTP 8080
⇩ ⇖
⇧ Docker container
Host machine HTTP 8081
The problem I'm having is that the Docker container cannot connect to the website on the host machines 8080. I'm not sure why, because I set the --network=host flag, so shouldn't it be using the host machines network?
This is my Docker image:
## Redacted irrelevant stuff...
EXPOSE 8080 8081
This is how run the container:
docker run -d -p 8080:8080 -p 8081:8081 --network=host --name=app app
Any ideas what's wrong with my setup?
So you have two services running directly on the machine and you want to deploy a Docker container that should connect to one of those services.
In that case, you shouldn't map those port to the container and you shouldn't expose those ports in the Dockerfile as those ports are not for the container.
Remove the Expose ports from the Dockerfile
Start the container using docker run -d --network=host --name=app app. The container should be able to access the services using localhost:8080.

How can I access both ports 8080 and 9990 on bluemix single container for wildfly?

I'm trying to run a Wildfly image on a Bluemix single container and I need to access both ports 9990 (default admin) and 8080 (deafault public); the problem is I can only get access to 8080.
So far I've build a simple docker image from the following Dockerfile:
FROM jboss/wildfly-camel
RUN /opt/jboss/wildfly/bin/add-user.sh admin password
EXPOSE 8080 9990
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
Locally everything works just fine if I run:
docker run -it -p 8080:8080 -p 9990:9990 myimage:tag
On Bluemix container I'm not able to access to port 9990 even if it does result mapped from cf ic ps -a:
I've got the same error creating container either by CLI or Web GUI.
Is there something I'm doing wrong?
2016 Feb 05 : UPDATE : the port 9990 is now available.
IBM Bluemix containers whitelist the ports that can be exposed and 9990 is not on the list.
You can try use an alternative port (like 9090 for example) or open a ticket with Bluemix support team and request port 9990 to be opened:
http://ibm.biz/bluemixsupport
PS: For security reasons the list of open ports are not externally documented.

Resources