Can't deploy spring application using WSL - spring

The software I'm trying to deploy is https://github.com/gitbitex/gitbitex-new
To sum up, it works. But only on linux machines.
Here is the script I used (from github).
# start zookeeper
docker run -d --name zookeeper-server \
--network host \
-e ALLOW_ANONYMOUS_LOGIN=yes \
bitnami/zookeeper:latest
# start kafka
docker run -d --name kafka-server \
--network host \
-e ALLOW_PLAINTEXT_LISTENER=yes \
-e KAFKA_CFG_ZOOKEEPER_CONNECT=127.0.0.1:2181 \
bitnami/kafka:latest
# start redis
docker run -d --name redis-server \
--network=host \
redis
# start mysql
docker run -d --name mysql \
--network=host \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7
# Please wait for MySQL to start before executing the following command
docker exec -it mysql mysql -uroot -p123456 -e "create database gitbitex;"
# start gitbitex
# open the browser and visit http://127.0.0.1/trade/BTC-USDT
docker run -d --name gitbitex \
--network=host \
greensheng/gitbitex
Firstly, I've tried to deploy it on vds using guide on github. And it worked without any problem.
Then I've tried to deploy it on my local machine which uses wsl with docker(integration is enabled) and it didn't work. Just can't load the webpage in browser. Curl from wsl also doesn't work, it says: connection refused.
Tried to deploy on a different linux machine, it worked again.
Tried different configuration using docker compose(cause this is what I'll need to do next). I've almost figured out how to setup it without network_mode: host but spring app itself throws exceptions anyway. With network_mode: host it doesn't work even on remote machine(but maybe it's my bad), but all containers are running properly, without errors.

It works on linux machine, but doesn't on Windows. As David Maze told in comments, it's because --network=host doesn't work on docker desktop.
I'll try instead to setup networking put everything into compose and make it work.
UPD: spent a lot of time trying to setup it without --network=host using docker compose and.. it still doesn't work on Windows. Docker destop is weird..

Related

Serving web page with Docker using custom /etc/host on host machine

I have added a host/ip to my macbook pro's /etc/hosts file. So something like:
192.168.0.0 example.test
What I would like to do is run a web server with Docker that utilizes the hostname, instead of 'localhost'
I can't figure out how to make this work. I have a laravel project running, and can make it serve to localhost with Docker via:
php artisan serve --host=0.0.0.0
I have tried using the --add-host flag with Docker's run command when I start the container. So something like:
docker container run -it -p 80:80 -v $(pwd)app --add-host example.test:192.168.0.0 my-custom-container bash
Any help would be greatly appreciated. I am pretty stuck.
The --hostname argument provides the hostname of the container itself.
docker container run --hostname example.test -it -p 80:80 -v $(pwd)app --add-host example.test:192.168.0.0 my-custom-container bash
Example:
$ docker run -it debian
root#2843ba8b9de5:/# hostname
2843ba8b9de5
root#2843ba8b9de5:/# exit
$ docker run -it --hostname foo.example.com debian
root#foo:/# hostname
foo.example.com
root#foo:/#

How do I expose ports on Heroku with a Dockerfile?

I am trying to deploy a Docker image on Heroku and am trying to understand how to expose multiple ports. Here is the Docker command that I am trying to run in the Heroku deploy:
docker run \
-p 2222:22 \
-p 33306:3306 \
-p 27017:27017 \
-p 28015:28015 \
-p 29015:29015 \
-p 8080:8080 \
test/db-migration
How do I do this in Heroku?
You can't - you should use the $PORT environment variable which will be randomly assigned and then mapped to port 80 by the Heroku routers. Also, only http requests are accepted. See https://devcenter.heroku.com/articles/container-registry-and-runtime#dockerfile-commands-and-runtime for more details.
You may want to look at Dockhero add-on. It's a good way to deploy supplementary resources alongside your Heroku app, and it supports docker-compose with multi-port mapping. The web app itself should still be running on Heroku dynos.

How to remove docker container using port number

I have Node services which are running in Docker container
I am using shell script to run these services
I want to run three different instances of the same service on 3 different port. say 9011 9022 9033
I also want it to configure it in such a way that after every new deployment it should stop the previous service and remove it
I am using docker rm test-service to remove it but it will remove other instances too.
by this approach only once instance can be running.
Is there any way to remove Docker service running on the specific port.
here is my shell script
#!/bin/bash
ORGANISATION="$1"
SERVICE_NAME="$2"
VERSION="$3"
ENVIRONMENT="$4"
INTERNAL_PORT_NUMBER="$5"
EXTERNAL_PORT_NUMBER="$6"
NETWORK="$7"
docker build -t ${ORGANISATION}/${SERVICE_NAME}:${VERSION} --build-arg PORT=${INTERNAL_PORT_NUMBER} --build-arg ENVIRONMENT=${ENVIRONMENT} --no-cache .
docker stop ${SERVICE_NAME}
docker rm ${SERVICE_NAME}
sudo npm install
sudo npm install -g express
docker run -p ${EXTERNAL_PORT_NUMBER}:${INTERNAL_PORT_NUMBER} --network ${NETWORK} --name ${SERVICE_NAME} --restart always -itd ${ORGANISATION}/${SERVICE_NAME}:${VERSION}
I can not run more than one container with the same name. Can I run the docker service with the same name on 3 different port. if yes what modifications do i need to make in above shell file?
That would be three docker run, each using the same internal port, but mapped to a different host port, with three different names
docker run -p ${EXTERNAL_PORT_NUMBER1}:${INTERNAL_PORT_NUMBER} --name ${SERVICE_NAME1}
docker run -p ${EXTERNAL_PORT_NUMBER2}:${INTERNAL_PORT_NUMBER} --name ${SERVICE_NAME2}
docker run -p ${EXTERNAL_PORT_NUMBER3}:${INTERNAL_PORT_NUMBER} --name ${SERVICE_NAME3}
I want to perform LoadBalance for service
See docker swarm mode
The swarm manager uses ingress load balancing to expose the services you want to make available externally to the swarm.
The swarm manager can automatically assign the service a PublishedPort or you can configure a PublishedPort for the service. You can specify any unused port. If you do not specify a port, the swarm manager assigns the service a port in the 30000-32767 range.
Example:
the following command publishes port 80 in the nginx container to port 8080 for any node in the swarm
$ docker service create \
--name my-web \
--publish 8080:80 \
--replicas 2 \
nginx

Connecting to rethinkdb (or any other app running on an http port) from the Docker OS X beta

I've installed the Docker for Mac beta which allows you to use docker commands directly. I want to try to run rethinkdb through docker, so I've followed the instructions of the rethinkdb docker container docs and done the following:
docker run --name some-rethink -v "$PWD:/data" -d rethinkdb
This works, and I can see the container with docker ps and start shell with docker exec -it /bin/bash
However, I can't connect to the admin panel on my Mac directly with their suggestion
$BROWSER "http://$(docker inspect --format \
'{{ .NetworkSettings.IPAddress }}' some-rethink):8080"
This essentially amounts to google-chrome http://172.17.0.2:8080/, but this doesn't work. I asked around and was told
You can't use the docker private ip address space to access the ports
You have to forward them to the mac
However, I'm not sure how to do this as I don't have any port forwarding tools I'm familiar with such as ssh on the container itself. Using the suggested port forwarding command in the rethinkdb container docs ssh -fNTL ... but with localhost instead of remote does not work.
How can I connect to the rethinkdb admin panel through http with the docker beta on a Mac?
Try forwarding the container port using the -p flag in the docker run command, e.g.:
docker run -p 8080:8080 --name some-rethink -v "$PWD:/data" -d rethinkdb
and then it should be accessible on localhost,
google-chrome http://127.0.0.1:8080/
Relevant docker run docs: https://docs.docker.com/engine/reference/run/#/expose-incoming-ports

Spark Docker - Can't access web UI for resource manager - Mac PC

Can't access resource manager web ui - Spark docker container - Mac PC
These are the steps that I did:
docker pull sequenceiq/spark:1.6.0
docker run -it -p 8088:8088 -p 8042:8042 -p 4040:4040 -h sandbox sequenceiq/spark:1.6.0 bash
I tested using this: ( Runs fine )
run the spark shell
spark-shell \
--master yarn-client \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores 1
execute the the following command which should return 1000
scala> sc.parallelize(1 to 1000).count()
But can't access the web ui:
I tried:
a. :8088
b: http://sandbox:8088/proxy/application_1458858022274_0002/A
c: localhost:8088
Nothing works.. Any help ??
Thanks in advance!!
You need to expose the ports before publishing them. Either EXPOSE 8088 8042 4040 in the Dockerfile or -e 8088 -e 8042 -e 4040 in your run command. Expose functionality is separated from publish/host mapping functionality because there are cases where one would like to expose to port to other containers without mapping it to the host.

Resources