Host port binding with Docker Stack for Windows Container - windows

I want to use Docker stack deployment for my application. When I try to make a binding between my host and the container, it crashes and restarts in a loop.
Everything works when I use docker-compose or docker service
My config:
Windows 10 Pro
Docker v20.10.12
IIS Windows Container with Hyper-V isolation (Does not work with process isolation either)
stack.yml:
version: "3.9"
services:
site:
image: iis-site:latest
hostname: iis-test
isolation: 'hyperv'
proxy:
image: iis-proxy:latest
hostname: iis-proxy
isolation: 'hyperv'
deploy:
mode: global
ports:
- target: 80
published: 80
protocol: tcp
mode: host
Do you have any idea how to solve this problem?

Related

Docker containers not logging to loki using loki log driver

I'm trying to use the loki log driver in a docker container on an AWS ec2 host. The config below works fine on my own ubuntu 20.04 machine but not in an ubuntu 16.04 ec2 host. iptables has a loopback rule and the appropriate docker port for loki, :3100. I even opened up that port in the security group. The docker version is 20.10.2.
I have tried to use localhost:3100, the hostname:3100, also the docker container name. I have a bridge network and don't want to use a host network. I also don't want to use the container IP address.
Nothing in this SO question works for me. How to access host port from docker container
Here is my docker-compose.yaml which works on my local machine but not in ec2.
the tools container is a go html server. The tools and loki containers are on the same host.
I can post a log to loki from an alpine container using curl to URL http://loki:3100/loki/api/v1/push but not from my tools container. I can connect with telnet but curl times out.
version: '3.3'
networks:
traefik:
external: true
loki: {}
services:
tools:
build: .
container_name: tools
restart: always
networks:
- traefik
- loki
extra_hosts:
- "host.docker.internal:host-gateway"
logging:
driver: loki
options:
loki-url: http://loki:3100/loki/api/v1/push
loki-external-labels: job=tools
labels:
...
Here is my loki docker-compose.yaml
version: "3.8"
networks:
traefik:
external: true
loki: {}
volumes:
loki_data:
services:
loki:
container_name: "loki"
image: grafana/loki:2.1.0
restart: always
networks:
- traefik
- loki
ports:
- 3100:3100
volumes:
- type: volume
source: loki_data
target: /data
- type: bind
source: ./config/s3-loki-bolt-conf.yml
target: /etc/loki/local-config.yaml
command: -config.file=/etc/loki/local-config.yaml
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
the docker plugin is installed
docker plugin ls
ID NAME DESCRIPTION ENABLED
a03c22e8375e loki:latest Loki Logging Driver true
sudo journalctl -u docker.service | grep loki is giving me this error.
08 06:46:06 docker1 dockerd[30842]: time="2021-02-08T06:46:06-08:00" level=info msg="level=warn ts=2021-02-08T14:46:06.586642758Z caller=client.go:322 container_id=5a5fbd8a7077243de9db74f549ab619f783eda978ee234651ad1849263a534fe component=client host=localhost:3100 msg=\"error sending batch, will retry\" status=-1 error=\"Post \\\"http://localhost:3100/loki/api/v1/push\\\": context deadline exceeded\"" plugin=fef8734ec8cc2d252f8c4e73e3e91fe8293d2847c7ce1d6df2fb2172a1c288ce

Can't connect to Docker sql for Windows by hostname

I have next docker compose file (part of it)
version: '3.7'
services:
# DB Server ==========================================================================================================
mssqlsimple:
image: microsoft/mssql-server-windows-developer:2017-latest
volumes:
- ".\\Prm.DbContext.Application\\FullInit:C:\\data"
container_name: pbpmssqlsimple
ports:
#- "1403:1433"
- target: 1433
published: 1403
protocol: tcp
mode: host
networks:
- backend
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "SP_116b626d-ed7e-4f5d123#"
...
after command docker-compose up i have instance of sql server and can to connect to it by IP (172.21.69.132) or alias id (0338726df5ba) from docker config.
but i can't connect by host name mssqlsimple (or pbpmssqlsimple)
fragment config json
I tried to do it, but failed
disable windows firewall
connect with port mssqlsimple, 1403
used simple syntax for ports "1403:1433"
Tell me please how to solve my problem

traefik proxy for docker container running in host network

i am running traefik as a proxy in docker container
i am using DockerToolBox in windows 10
the traefik proxy was able to recognize the service app which is running in 127.0.0.1, but the service app is actually running in docker host = 192.168.99.x ip
version: '3'
services:
reverse_proxy:
image: traefik
command: --api --docker
ports:
- "81:80"
- "8081:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- backend
whoami:
image: containous/whoami
labels:
- "traefik.frontend.rule=Host:whoami.default"
- "traefik.enable=true"
- "traefik.port=80"
network_mode: host
networks:
backend:
driver: bridge
in the Traefik dashboard http://192.168.99.100:8081
it shows http://127.0.0.1:80 for whoami service
instead of http://192.168.99.100:80
any help would be appreciated.
i want network_mode: host to pick 192.168.99.100 instead of 127.0.0.1
As traefik official documentation says, when resolving service IP, first it
try a lookup of host.docker.internal
and second
if the lookup was unsuccessful, fall back to 127.0.0.1
This means we can just add a host in the traefik container, using --add-host {docker0_IP}(it's the bridge's IP, you can easily use docker inspect {NAME_OF_TRAEFIK} and find the IP of Gateway(for me, it's 172.18.0.1). If you use docker-compose, you can use add following lines to your definition of traefik:
extra_hosts:
- host.docker.internal:{docker0_IP}
Also, I find that it's ok to use the IP my eth0 IP, which means the IP of your LAN(for me, it's 192.168.0.20).
Then, recreate traefik and everything works like a daisy.

Connect docker-compose container on Mac OS

Running docker-compose (1.23.2, build 1110ad01) on Mac OS I am having a hard time getting the IP address of my container. My compose file looks like this:
version: '3.4'
services:
secondcontainer:
image: myregistry/secondcontainer
networks: mynet
deploy:
replicas: 1
resources:
limits:
cpus: "1.0"
memory: 500M
restart_policy:
condition: on-failure
ports:
- "54000:54000"
networks:
- mynet
networks:
mynet:
I can see the two containers coming alive, and I can see that something is listening on port 54000
com.docke 28032 me 22u IPv4 0x2b3b4a41c30a8773 0t0 TCP *:54000 (LISTEN)
I am trying to access this container using a C# app running on the Mac. No matter what IP address I use, I can't seem to get through. I have tried 127.0.0.1:54000, I have tried the local IP of the Mac host, I have tried the IP address the container is assigned (172.25.0.3 as an example) with the right port. I have tried with nc, no luck there.
Same code works flawlessly on Linux. I know there may be issues with Docker on Mac, but isn't this a supported scenario?

Docker use ip from host

I have the problem, that I want to create multiple docker container (with docker-compose) and call each container with the ip address.
On a Linux host it works but not in Windows as host.
Example:
container 1 (php) ip: 192.168.100.10
container 2 (mysql) ip: 192.168.100.11
container 3 (nginx) ip: 192.168.100.12
so I want to add a hosts item with the ip of the nginx to use a hostname like project.local for develop on browser.
Have anyone a idea what I must do on windows to realize this?
Each container use a internal IP for the base system that you using with your containers, for example if you are using Linux all container will have an internal IP that can be seen between container, but not for the principal host, if you want to connect to the containers you will need to use the ports for example for MySQL 3306, if the containers aren't seen between it you will need to create links or networks using a docker compose or the bash to set up this configuration, here I adjunct an example:
https://docs.docker.com/compose/networking/#specify-custom-networks
version: "3"
services:
proxy:
build: ./proxy
networks:
- frontend
app:
build: ./app
networks:
- frontend
- backend
db:
image: postgres
networks:
- backend
networks:
frontend:
# Use a custom driver
driver: custom-driver-1
backend:
# Use a custom driver which takes special options
driver: custom-driver-2
driver_opts:
foo: "1"
bar: "2"
https://docs.docker.com/compose/networking/#links
version: "3"
services:
web:
build: .
links:
- "db:database"
db:
image: postgres

Resources