How do you change the port of Microsoft Form Recognizer on-premise? - containers

Microsoft Azure Form Recognizer as part of Cognitive Services can run in a container:
pull docker://mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout
You can run the container on the default port 5000.
But when you open a pod in podman with several ports. The MS form recognizer grabs all open ports 5000+. We would like to allow only one or two ports for this service.
podman pod create --name=my_pod -p 5000:5000 -p 5002:5002 -p 5008:8888
You can run and define the incoming ports with a command like this:
podman run --rm -it -d --name myFormRecognizer -p 5000:5000 --memory 16g --cpus 4 mcr.microsoft.com/azure-cognitive-services/vision/read:3.2-model-2022-04-30 Eula=accept Billing=https://cs-container.cognitiveservices.azure.com/ ApiKey=XXXX
But when using pods, ports are already defined when creating the pod. Thus the p-switch is not available running the container.
Is there a method to prevent MS Forms container using specific ports? Our workaround today is, running other services first, and MS forms last, when starting the pod.

Related

How to connect docker container with host machine's localhost mysql database?

I have a war file that uses the MySQL database in the backend.
I have deployed my war file in a docker container and I am able to ping this from my browser.
I want to connect my app with the MySQL database. This database exists on my host machine's localhost:3306
As I am unable to connect this from inside container's localhost, what I tried is,
I run a command docker inspect --format '{{ .NetworkSettings.IPAddress }}' 213be777a837
This command gave me an IP address 172.17.0.2. I went to MySQL server options and put this IP address in the bind field and restarted the server. After that, I have updated my projects database connection string with 172.17.0.2:3306
But it is not working. Could anyone please tell what I am missing?
I have also tried adding a new DB user with root#% and then run command allow all permission to 'root#%' but nothing worked.
Follow the steps:-
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
docker run -p 8082:8080 --network dockernet -d 6ab907c973d2
in your project set connection string : jdbc:mysql://host.docker.internal:3306/....
And then deploy.
tl;dr: Use 172.17.0.1:3306 if you're on Linux.
Longer description:
As I understand what you need to do is to connect from your Docker container to a host port. But what you have done is to try to bind the host process (MySQL) to the container networking interface. Not sure what the implications of a host process trying to bind to another host process network namespace, but IIUC your MySQL process should not be able to bind to that address.
When you start MySQL with default settings that bind it to 0.0.0.0 it's available for Docker containers through the Docker virtual bridge. Therefore, what you should do is to route your requests from the WAR process to the host process through that virtual bridge (if this is the networking mode you're using. If you have not changed any Docker networking settings, it should be). This is done by specifying the bridge gateway address as the MySQL address and the port it's started with.
You can get the bridge IP address by checking your network interfaces. When Docker is installed, it configures the virtual bridge by default, and that should show up as docker0 if you're on Linux. The IP address for this will most probably be 172.17.0.1. So your MySQL address from the container's point of view is jdbc:mysql://172.17.0.1:3306/....
1 - https://docs.docker.com/network/
2 - https://docs.docker.com/network/bridge/
From your question, I am assuming you both your war file and MySQL is deployed locally, and you want to connect them. One way to allow both containers that are locally deployed to talk to each other is by:
Create your own network docker network create <network-name>
Then when you run your war file and MySQL, deploy both of them using the --network. E.g.
War File: docker run --name war-file --network <network-name> <war file image>
MySQL: docker run --name mysql --network <network-name> <MySQL image>
After that, if you should be able to connect to your MySQL using mysql:3306 from inside your war file docker container, since they are both on the same custom network.
If you want to read up more about this, can take a look at docker documentation on network. (https://docs.docker.com/network/bridge/).
Your setup is fine. You just need to do this one change.
While running the application container (the one in which you are deploying your war file), you need to add following argument in its docker run command.
--net=host
Example:
docker run -itd -p 8082:8080 --net=host --name myapp myimage
With this change, you need not to change connection string as well. localhost:3306 would work fine. And you will be able to set up a connection with MySQL.

Connecting to percona docker from a java docker container

I know there have been many similar questions, but none of them are what I want. I'm following this because I specifically need 5.5, at least for now. My java project (which accesses mysql) is in a container I built with
docker build -t projectname-testing .
The Dockerfile is pretty standard, it just copies over a built tarball and extracts it to a specific folder. The CMD is a shell script run_dev_server.sh that just launches the server with dev configurations rather than production ones.
I created a percona docker container with the command given in the link with
docker run --name projectname-mysql-server -e MYSQL_ROOT_PASSWORD="" -d percona:5.5
So now the way I see it, just need the link the two as mentioned in the link:
docker run -p 3306:3306 --name projectname-local --link projectname-mysql-server projectname-testing
Which gives me
docker: Error response from daemon: Cannot link to a non running container: /projectname-mysql-server AS /projectname-local/projectname-mysql-server.
ERRO[0000] error getting events from daemon: net/http: request canceled
Which isn't very helpful and doesn't tell me what happened. Am I understanding this process wrong? What should I be doing?
First of all, I would recommend using the official Percona docker image from Docker Hub, instead of building your own image. The official image has a 5.5 version; https://hub.docker.com/_/percona/
You can either extend this image if you need specific changes (such as a custom configuration), for example;
FROM percona:5.5
COPY my-config.cnf /etc/mysql/conf.d/
Important: I notice you are publishing port 3306 (-p 3306:3306). Publishing a port makes it publicly accessible on the host's network-interface. You should only do this if you have external software that needs to connect to the database. If only your application needs access to the database, publishing the port is not needed, because containers can connect with eachother through the docker container-container network, which is "private" and not reachable from outside the host.
The --link option on the default network is a legacy option that is still around for backward compatibility, but should not be used for most situations. The --link option has a number of limitations;
legacy links are not dynamic; it's not possible to replace a linked container without re-creating all containers linked to that container
restarting a linked container can break the link, with no option to re-establish a link
legacy links are uni-directional
environment variables are shared between containers, which can easily lead to leaking (e.g.) credentials to other containers.
Docker 1.9 introduced custom docker networks, which allows
A simple example;
create a network for your application;
docker network create mynet
create a database container, and attach it to the network; there is no need to publish its ports for other containers to connect to it. (I'm using an nginx image here, just to illustrate the concept);
docker run -d --name db --network mynet nginx:alpine
create an "application" container and attach it to the same network; doing so
allows it to communicate with the db container over that network;
docker run -dit --name app --network mynet alpine sh
The application container can now connect to the db container, using its name
as hostname (db); to illustrate this, open a shell in the app container, install curl and connect to http://db:80;
docker exec -it app sh
/ # apk add --no-cache curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20161130-r1)
(2/4) Installing libssh2 (1.7.0-r2)
(3/4) Installing libcurl (7.52.1-r3)
(4/4) Installing curl (7.52.1-r3)
Executing busybox-1.25.1-r0.trigger
Executing ca-certificates-20161130-r1.trigger
OK: 5 MiB in 15 packages
/ # curl http://db:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
You can read more about networks (also how to dynamically attach and detach a container from a network) in the []"docker container networking" section of the documentation](https://docs.docker.com/engine/userguide/networking/)

Docker communication without using legacy links

I'm trying to create a mini-demo with docker using mysql and phpmyadmin and i'm trying to make the two docker containers communicate with each other without using the --link flag since this has been flagged as "legacy" by docker (https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#/connect-with-the-linking-system)
I managed to do this using docker-compose using the network section, but I want to implement the same scenario using normal dockerfiles and running the two containers in command prompt.
Here are the two dockerfiles I created:
Dockerfile for mysql
FROM mysql:5.7
ENV MYSQL_ROOT_PASSWORD=12345678
ENV MYSQL_DATABASE=mysql
ENV MYSQL_USER=user
ENV MYSQL_PASSWORD=12345678
Dockerfile for pma
FROM phpmyadmin/phpmyadmin:4.6
ENV PMA_HOST=mysql
ENV MYSQL_ROOT_PASSWORD=12345678
Docker images are created correctly using docker build and these are the commands that i use to run the two containers:
mysql:
docker run -d --name mysql sebastian/db-mysql
pma:
docker run -d -p 7777:80 --name pma sebastian/db-pma
When i try to connecto to Pma using username root and password 12345678 i get the following error:
mysqli_real_connect(): (HY000/2005): Unknown MySQL server host 'mysql' (-2)
I'm sure I'm missing something when spinning the two containers and I cannot fully understand how the two containers are suppose to communicate and/or how pma will find host mysql (the name i defined when running the mysql container)
Is docker suppose to allow communication between the two containers?
How do containers should find each other by using names and not ip addresses?
P.S. i'm using dockertoolbox on windows 10 (maybe that is the real problem :D )
The problem:
You are not specifying any networks in your docker run so you will use default bridge, Default bridge will not give you internal DNS but containers on that network can communicate via IP Addresses.
Follow these steps:
First create a user-defined network:
docker network create <yournetworkname>
Now run containers using the network we just created:
docker run -d --name mysql --network <yournetworkname> sebastian/db-mysql
docker run -d -p 7777:80 --name --network <yournetworkname> pma sebastian/db-pma
User defined networks provide connectivity by default and internal dns to the containers on the same network. For example you can ping mysql from pma by:
ping mysql

Connect docker container to local workbench MySQL DB

HI I have my web app running on my local machine and connected to Mysql workbench, I am now trying to dockerize the webapp. I can't seem to get it to connect to the DB on my local dev machine (I am running Docker Desktop for Windows), can anyone tell me how I would go about this? Here is what I have so far.
`docker run -it -e "CATALINA_OPTS=-Dspring.profiles.active=dev -DPARAM1=DEV" -p 8080:8080 -p 8005:8005 -p 8009:8009 -p 3306:3306 --add-host=docker:192.168.1.7 -v C:\myapp\trunk\target\myapp.war:/usr/local/tomcat/webapps/myapp.war --name waitapp tomcat:8.0.38-jre8`
after a few second, I run docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a1764dd9640 tomcat:8.0.38-jre8 "catalina.sh run" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp, 0.0.0.0:8005->8005/tcp, 0.0.0.0:8009->8009/tcp, 0.0.0.0:8080->8080/tcp waitapp
The container seems to be running, but I get a 404 Not found when I try the rest request, this is the same as I do when running from inside spring tool suite using built in tomcat server.
NOTE
I don't want to run a separate mysql container and link the two over a network, I just want to try get my newly created docker app to connect to my local DB MySQL.
As mentioned on this post, you can try 2 things:
Add gateway and use it from containers, like
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
In addition to your app container, run proxy (ngnix?) container, which will rout the calls to DB when required
This answer also show how can you obtain the host IP inside the docker container.

docker.io - Docker linking between application & database containers

I am trying to use my Scala-Akka application with my MySQL database on two separate Docker containers. I found out that Docker allows developers to link their application to their databases with the flag named --link. In my Dockerfiles in which I've used to create my images, I have add in EXPOSE 3306 8080 to it.
And this is how I run the containers:
docker run -d -p 3306:3306 --name mysql centos6mysql
docker run -d -p 8080:8080 --name scalaapp --link mysql:db centos6scala
After running the containers, I used docker ps and I am able to see the active containers. However, It seems like the application container is not using the database from the MySQL container. Anyone know what's wrong?
Linking in Docker allows network connections to be made between containers. Docker will define environmental variables to your linked containers for the URL, IP, port, and protocol. The names of these will be based on the name of your container. For instance:
DB_NAME=/web2/db
DB_PORT=tcp://172.17.0.5:5432
DB_PORT_5432_TCP=tcp://172.17.0.5:5432
DB_PORT_5432_TCP_PROTO=tcp
DB_PORT_5432_TCP_PORT=5432
DB_PORT_5432_TCP_ADDR=172.17.0.5
You can use these environmental variables to set up your Akka app container to connect to your DB container. However, you must manually configure the app container to do so. Docker will not make the connection for you automatically.
So, somewhere in your app, you will need to pass these values to your startup script, something that might look like:
./restcore --Ddb.default.db="jdbc:mysql//${DB_PORT_3306_TCP_ADDR}:${DB_PORT_3306_TCP_PORT"