Docker swarm service port not exposed - docker

I cannot connect to a service running on docker swarm. The swarm seems ok because I can connect to other containers running on it. I running the service with docker stack deploy -c docker-compose.yaml nifi and the docker compose file is:
version: "3.3"
services:
registry:
image: apache/nifi-registry:0.3.0
ports:
- "18080:18080"
deploy:
replicas: 1
restart_policy:
condition: on-failure
When I run this without the swarm i.e. docker-compose -f docker-compose.yaml up it works fine and I can browse to it. When I run it with docker stack deploy -c docker-compose.yaml nifi I see the same log entries for the service but cannot browse to it.
$ docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Wed Jun 20 21:43:51 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Wed Jun 20 21:42:00 2018
OS/Arch: linux/amd64
Experimental: false
Does anyone have suggestions for fixing or troubleshooting this?

In swarm
ports:
- "18080:18080"
will expose port on all swarm nodes and in case of use of the port on some of the nodes by another service you can have problems
you can expose port only on host with container
services:
registry:
ports:
- target: 18080
published: 18080
mode: host

Related

How to connect to host machine from a Windows-Container with transparent network driver

I'm using a Windows-Image container with a transparent network driver:
Host SO: Windows 10 Pro
Container Image:
mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019
C:\>docker version
Client:
Cloud integration: v1.0.22
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:13:04 2022
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.6.0 (75818)
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.24)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:08:21 2022
OS/Arch: windows/amd64
Experimental: true
Network used:
docker network create --driver transparent -o com.docker.network.windowsshim.interface="Ethernet 7" --subnet 10.61.1.0/24 --gateway 10.61.1.254 MY_NETWORK
Command to run the container:
docker run --net MY_NETWORK --ip 10.61.1.120 --add-host=host.docker.internal:host-gateway -it --name TEST_1 testimage cmd.exe
I can ping the host from within the container and viceversa.
But when I try to call a service runnig on the host, the 'host.docker.internal' is not resolved:
The host file in the host machine (10.61.1.102) is:

Docker Swarm: docker stack deploy fails when executed second time

I have a single node docker swarm which has just been created with docker swarm init.
I have a docker-stack.yml which contains the following deployment:
version: '3.3'
services:
website:
image: docker.pkg.github.com/foo/bar/bar:latest
ports:
- "80:80"
- "443:443"
environment:
HOST: bar.com
secrets:
- site.key
- site.cert
networks:
- foo-net
networks:
foo-net:
driver: overlay
external: true
secrets:
site.key:
external: true
site.cert:
external: true
First, I login into the registry and it tells me that the login was successful.
Second, I deploy the stack
$ docker stack deploy --with-registry-auth --compose-file docker-stack.yml foo
Creating service foo_bar
After that, the service is running and everything works as expected.
However, when I try to deploy a stack with the same command a second time (a few seconds later), it fails with the following message.
$ docker stack deploy --with-registry-auth --compose-file docker-stack.yml foo
Updating service foo_website (id: uvtqpdx74784dy9egj5i1c7sb)
image docker.pkg.github.com/foo/bar/bar:latest could not be accessed on a registry to record
its digest. Each node will access docker.pkg.github.com/foo/bar/bar:latest independently,
possibly leading to different nodes running different
versions of the image
Why does this happen?
All networks and secrets are created beforehand and my docker version is:
$ docker version
Client:
Version: 19.03.6
API version: 1.40
Go version: go1.12.17
Git commit: 369ce74a3c
Built: Fri Feb 28 23:45:43 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.6
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: 369ce74a3c
Built: Wed Feb 19 01:06:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.3-0ubuntu1~18.04.2
GitCommit:
runc:
Version: spec: 1.0.1-dev
GitCommit:
docker-init:
Version: 0.18.0
GitCommit:
I appreciate any help!
Thanks

Docker compose allow a service to access a db on the host via hostname

Hello everyone i am just beginning docker and really appreciate the whole container concepts but one thing i cant seem to figure out is that when i use docker compose to define my services i have to give a network also and all containers connect to that network and hence are reachable to one another but what if my one service needs to connect to a database service hosted on localhost.How will my service be able to reach the database i have searched about networking mode host and net:host options in compose file but they don't seem to work my docker version info is as follows.
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false
my docker-compose.yml file
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: dbaccessserviceimage
network_mode: "host"
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
Really need help as i am designing the architecture to move all our production into containers A docker compose file with appropriate version and network option would be highly appreciated.

Docker compose creates network with different subnet each time

I have a simple yaml file which starts two containers: JBoss and Postgres. When I run:
docker-compose -f compose-application.yaml up -d
new network is created - this is what I expect. However, when I stop containers with:
docker-compose -f compose-application.yaml down
and start them once again then network gets new subnet (increased by 1). When restart is repeated few times then subnet assigned conflicts with already existing one (problem with routing etc.).
I know I can specify subnet which should be used inside yaml. However, I tried to run this on different machine (Docker for Windows 7) and there this network gets the same subnet each time.
I am using docker version:
docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:29 2018
OS/Arch: linux/amd64
Experimental: false
and docker compose:
docker-compose version
docker-compose version 1.23.1, build b02f1306
docker-py version: 3.5.0
CPython version: 3.6.7
OpenSSL version: OpenSSL 1.1.0f 25 May 2017
I don't know why it works differently in Windows 7, but I can imagine that's because Docker machine itself.
I think the best solution it's really define a network on docker-compose yml file. Something like this:
networks:
network_name:
name: NETWORK_NAME
driver: bridge
ipam:
config:
- subnet: SUBNET

Network undefined issue in docker stack

I am using docker stack to deploy some services on a swarm network with two nodes . I created overlay network which I can see through
docker network ls but when I am trying to use that network in docker stack file I am continuously getting error Network undefined .
Here is my docker stack file
version: '3.4'
services:
orderer1st:
image: hyperledger/fabric-orderer:1.2.1
networks:
- fabricoverlay
ports:
- 7050:7050
environment:
- ORDERER_GENERAL_LOGLEVEL=info
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
command: orderer
volumes:
- ./channel-configuration/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./msp:/var/hyperledger/orderer/msp
Am I doing something wrong here? I dont know why docker stack is been unable to pick overlay network
Docker Version:
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:24:56 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:21 2018
OS/Arch: linux/amd64
Experimental: false
You have to add the networks as root objects in the compose file so the service knows how to find it.
networks:
fabricoverlay:
external: true
Note that an easier option might be letting swarm create that network for your stack. Just remove the network references in the compose file, delete the manually created network, and deploy the stack. Docker will create it for you, one network per stack.

Resources