Change default port for swagger-ui dist bundle - swagger-ui

How would you go about changing the default port of swagger-ui dist version?
By default it listens to requests on port 8080. I want it to listen to some other port. The use case is that we want to have a couple of dists running on our host but listening on different ports.
Is this possible or do you actually need to do some more complicated setup?
We run it via node js default package:
{
"name": "dist",
"version": "1.0.0",
"description": "",
"main": "swagger-ui-bundle.js",
"scripts": {
"start": "http-server"
},
"keywords": [],
"author": "",
"license": "ISC"
}

The simples solution that I know Is just to use docker and map port by -p 80:8080:
https://hub.docker.com/r/swaggerapi/swagger-ui/
docker run -p 80:8080 -e API_URL=http://generator.swagger.io/api/swagger.json swaggerapi/swagger-ui
In case if you not use API_URL here is docker file for above docker - you cna use this information SWAGGER_JSON "/app/swagger.json" to map path to swagger.json in your local machine (using docker --volume parameter)

Related

How to debug golang with dlv in remote container with vscode

recently I need to do debug for a single file go binary application which is contained in the docker under k8s environment with its source code. When I package the docker I use the
/dlv --listen=:40000 --headless=true --api-version=2 exec /singleExeFile
and expose the 40000 port to the outer VM like
ports:
- 40000:40000
When I use my dev environment to connect to outer vm with dlv command. It seems that it can be connected. Like the following
foo#foo-vm:~$ dlv connect 110.123.123.123:40000
Type 'help' for list of commands.
(dlv)
But when use vscode to attach to the code, it meets two error(The vscode has installed go extension)
When use legacy connect, there is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"debugAdapter": "legacy",
"request": "attach",
"mode": "remote",
"port": 40000,
"host": "110.123.123.123",
"substitutePath": [
{
"from": "${workspaceFolder}/cmd/maine.go",
"to": "/singleExeFile"
}
]
}
]
}
But the vscode raises error and I haven't found similar error in google. Error: Socket connection to remote was closed
Use the dlv-dap method to connect
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Delve into Docker",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "attach",
"mode": "remote",
"port": 40000,
"host": "110.123.123.123",
"substitutePath": [
{
"from": "${workspaceFolder}/cmd/maine.go",
"to": "/singleExeFile"
}
]
}
]
}
And when try to connect, there is no error raised by vscode. Just try to connect and stop by vscode. Even don't know what's the error.
With verbose param, there still isn't any output in the DEBUG console for dlv method. But for legacy method, the following error is outputted. Please check.
By the way, add verbose in legacy method and it raises some detailed message in DEBUG CONSOLE.
AttachRequest
Start remote debugging: connecting 110.123.123.123:40000
To client: {"seq":0,"type":"event","event":"initialized"}
InitializeEvent
To client: {"seq":0,"type":"response","request_seq":2,"command":"attach","success":true}
From client: configurationDone(undefined)
ConfigurationDoneRequest
Socket connection to remote was closed
To client: {"seq":16,"type":"response","request_seq":2,"command":"attach","success":false,"message":"Failed to continue: Check the debug console for details.","body":{"error":{"id":3000,"format":"Failed to continue: Check the debug console for details.","showUser":true}}}
Sending TerminatedEvent as delve is closed
To client: {"seq":0,"type":"event","event":"terminated"}
From client: disconnect({"restart":false})
DisconnectRequest
New Update in 9 July
I made another try to create a simple docker using the following dockerfile
FROM golang:1.16.15
RUN mkdir -p /var/lib/www && mkdir -p /var/lib/temp
WORKDIR /var/lib/temp
COPY . ./
RUN go env -w GOPROXY="https://goproxy.cn,direct"
RUN go install github.com/go-delve/delve/cmd/dlv#latest
RUN go mod tidy
RUN go build
RUN mv ./webproj /var/lib/www/ && rm -rf /var/lib/temp
WORKDIR /var/lib/www
COPY ./build.sh ./
EXPOSE 8080
EXPOSE 2345
RUN chmod 777 ./webproj
RUN chmod 777 ./build.sh
ENTRYPOINT ["/bin/bash","./build.sh"]
And the build.sh code is like
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./webproj
After that, it works with GoLand debug. GoLand can debug when I send the GET api with designed. But it still can't be work with VSCode. When I use the vscode, it did connect to the docker. But when I add the break point. It shows that this is an unverified BreakPoint and can't stop.
Here is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${fileDirname}",
"port": 2345,
"host": "127.0.0.1"
}
]
}
So currently this is blocked. Help is very needed. Thanks.

How to expose docker port with host in a Elastic Beanstalk Docker environment?

Current environment :
I'm having an issue in my Beanstalk docker environment of exposing the expected port throughout the host. I can see my docker container has been running successfully inside the docker daemon but I cannot expose it via port 8080 on the beanstalk endpoint, but which is working with port 80.
Issue : I'm trying to access my EB endpoint using the same port(8080) where I'm using in dockerfile. But how can I do that?
Here is the output of docker ps
Here is my sample Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "123456789.dkr.ecr.us-east-1.amazonaws.com/registry",
"Update": "true"
},
"Ports": [
{
"ContainerPort": 8080,
"HostPort": 8080
}
],
"Volumes": [
{
"HostDirectory": "/path/to/log",
"ContainerDirectory": "/path/to/log"
}
]
}
you should create container with -p 8080:80 args, as I see you did it with -p 8080.

Getting the empty response from the server even when the container is port mapped in docker

I am trying to start my application using the http-server through npm start. It is working fine in the localhost but when i deploy the same application through docker container (port-mapped) , it doesn't appear in my local browser.
I have a directory inside my docker container(Ubuntu) which is runned through the command
docker run -it -p 8001:5500 ubuntu.
I have installed everything inside my container - npm, vim editor ,etc.
My package.json file is
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "http-server -a localhost -p 5500"
},
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^5.0.2",
"http-server": "^0.12.1"
}
}
After that i have done npm install and then executed the command npm start.
The output of the command is :
But when i am trying to open my application in chrome browser it is throwing me an empty response.
Also when i am running the same application through my localhost it is accessible.
Why i am not able to access the server through the port mapping of docker container.??
localhost inside container won't be accessible from outside the container. Run your server on 0.0.0.0 inside the container.

Rabbitmq connection refused from Docker container to local host

I have a docker container running a java process that I am trying to connect to rabbitmq running on my localhost.
Here are the steps I've done so far:
On my Local machine (macbook running Docker version 1.13.0-rc3, build 4d92237 with firewall turned off)
I've updated my rabbitmq_env.conf file to remove RABBITMQ_NODE_IP_ADDRESS so I am not tied to connect via localhost and i have an admin rabbitmq user. (not trying with guest user)
I tested this via telnet on my local machine and have no issues telnet <local-ip> 5672
Inside my docker container
able to ping local-ip and curl rabbitmq admin api
curl -i -u username:password http://local-ip:15672/api/vhosts returns sucessfully
[{"name":"/","tracing":false}]
When i try to telnet from inside the container I get
"Connection closed by foreign host"
looking at the rabbitmq.logs
=ERROR REPORT====
closing AMQP connection <0.30526.1> (local-ip:53349 -> local-ip:5672):
{handshake_timeout,handshake}
My java stacktrace incase helpful
Caused by: java.net.ConnectException: Connection refused (Connection >refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at >java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at >java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.>java:206)
at >java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at >com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.ja>va:32)
at >com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newCon>nection(RecoveryAwareAMQConnectionFactory.java:35)
docker network inspect bridge
[
{
"Name": "bridge",
"Id": "716f935f19a107225650a95d06eb83d4c973b7943b1924815034d469164affe5",
"Created": "2016-12-11T15:34:41.950148125Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Containers": {
"9722a49c4e99ca5a7fabe56eb9e1c71b117a1e661e6c3e078d9fb54d7d276c6c": {
"Name": "testing",
"EndpointID": "eedf2822384a5ebc01e5a2066533f714b6045f661e24080a89d04574e654d841",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
What am I missing?
for me this works fine!
I have been installed the image docker pull rabbitmq:3-management
and run
docker run -d --hostname haroldjcastillo --name rabbit-server -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin2017 -p 5672:5672 -p 15672:15672 rabbitmq:3-management
the most important is to add the connection and management ports -p 5672:5672 -p 15672:15672
See you host in docker
docker-machine ip
return in my case:
192.168.99.100
Go to management http://192.168.99.100:15672
For Spring Boot you can configure this or works good for another connections
spring.rabbitmq.host=192.168.99.100
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin2017
spring.rabbitmq.port=5672
Best wishes
For anyone else searching for this error, I'm using spring boot and rabbitmq in docker container, starting them with docker compose. I kept getting org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused from the spring app.
The rabbitmq hostname was incorrect. To fix this, I'm using the container names in the spring app configuration. Either put spring.rabbitmq.host=my-rabbit in spring's application.properties (or yml file), or in docker-compose.yaml add environment: SPRING_RABBITMQ_HOST: my-rabbit to the spring service. Of course, "my-rabbit" is the rabbitmq container name described in the docker-compose.yaml
I am using docker with linux container with rabbitmq:3-management and have created a dotnet core based web api. While calling from We API action method I faced the same issue and changed the value to "host.docker.internal"
following scenario worked for me
"localhost" on IIS Express
"localhost" on Docker build from Visual Studio
"host.docker.internal" on Docker build from Visual Studio
"Messaging": {
"Hostname": "host.docker.internal",
"OrderQueue": "ProductQueue",
"UserName": "someuser",
"Password": "somepassword" },
But facing the same issue when, the container created via docker build command, but not when container created using Visual Studio F5 command.
Now find the solution there are two ways to do it:
by default all the containers get added into "bridge" network go through with these steps
Case1: If you have already containers (rabbitmq and api) in the docker
and running then first check their ip / hostname
docker network ls
docker network inspect bridge # from this step you'll get to know what containers are associated with this
find the rabbitmq container and internal IP, apply this container name or IP and then run your application it will work from Visual Studio and Docker build and run command
Case2: if you have no containers running then you may like to create
your network in docker then follow these steps:
docker network create givenetworknamehere
add your container while using "docker run" command or after
Step2.1: if using docker run command for your container then;
docker run --network givenetworknamehere -d -p yourport:80 --name givecontainername giveyourimagename
Step2.2 if adding newly created network after container creation then use below
command docker network connect givenetworknamehere givecontainername
with these step you bring your container in your newly created same network and they can communicate.
Note: by default "bridge" network type get created
After a restart, all was working. I don't think Rabbit was using respecting .config changes

Docker's containers communication using Consul

I have read about service discovery for Docker using Consul, but I can't understand it.
Could you explain to me, how can I run two docker containers, recognize from the first container host of the second using Consul and send some message to it?
You would need to run Consul Agent in client mode inside each Docker container. Each Docker Container will need a Consul Service Definition file to let the Agent know to advertize it's service to the Consul Servers.
They look like this:
{
"service": {
"name": "redis",
"tags": ["master"],
"address": "127.0.0.1",
"port": 8000,
"checks": [
{
"script": "/usr/local/bin/check_redis.py",
"interval": "10s"
}
]
}
}
And a Service Health Check to monitor the health of the service. Something like this:
{
"check": {
"id": "redis",
"name": "Redis",
"script": "/usr/local/bin/check_redis_ping_returns_pong.sh",
"interval": "10s"
}
}
In the other Docker Container your code would find the Redis service either via DNS or the Consul Servers HTTP API
dig #localhost -p 8500 redis.service.consul
curl $CONSUL_SERVER/v1/health/service/redis?passing

Resources