docker stack deploy with docker-compose and publish a port number - docker-swarm

I just want to have a Nginx container running and publish on port 80
Update: I can see that this has also happened in previous versions:
https://github.com/moby/moby/issues/32111
I am running:
docker version
Client:
Version: 17.11.0-ce
API version: 1.34
Go version: go1.8.3
Git commit: 1caf76c
Built: Mon Nov 20 18:37:39 2017
OS/Arch: linux/amd64
Server:
Version: 17.11.0-ce
API version: 1.34 (minimum version 1.12)
Go version: go1.8.3
Git commit: 1caf76c
Built: Mon Nov 20 18:36:09 2017
OS/Arch: linux/amd64
Experimental: false
I am running this on digitalocean and I can see this when sudo lsof -iTCP -sTCP:LISTEN -P:
sshd 1522 root 3u IPv4 15971 0t0 TCP *:22 (LISTEN)
sshd 1522 root 4u IPv6 15973 0t0 TCP *:22 (LISTEN)
dockerd 5025 root 6u IPv6 28455 0t0 TCP *:2376 (LISTEN)
dockerd 5025 root 23u IPv6 227368 0t0 TCP *:2377 (LISTEN)
dockerd 5025 root 29u IPv6 227378 0t0 TCP *:7946 (LISTEN)
docker-compose.yml
version: "3"
services:
website:
image: my/nginx
ports:
- "80:80"
expose:
- "80"
And then how to starting the service - tried this:
docker stack deploy --compose-file docker-compose.yml stackdemo
But how do you publish the port?
I can see that I can do this from the terminal?
docker service create --name my_web \
--replicas 3 \
--publish target=8080,port=80 \
nginx
But I can not figure out how from docker-compose, do you know?

After our discussion in the comments; it's very likely that your container is failing and restarting - rather than your port isn't exposed.
Your initial compose file is perfect - except the expose arguments are actually unnecessary; but Docker will ignore them either way and your service will come online.
So what's happening here is your service was successfully created and now Docker Swarm will keep an eye on your containers - if they fail, it will bring them back online. So checking if you check for running services with docker service ls you will see yours online.
Now the tricky part here; is to figure out why your containers are failing. Likely the container will be restarting when you check, so use docker ps -a to show all containers, including the stopped ones.
Check for the latest one, and take the "Container ID" and run docker logs container_id to find out why your container is failing - solve that, rebuild your image, and update your service to use it - and you should be good to go!

Related

Why can't I lookup other container by DNS in container

According to official Docker's doc, Docker will create DNS server when it started which makes it able to query other container directly by container ID or name.
containers that use a custom network use Docker’s embedded DNS server, which forwards external DNS lookups to the DNS servers configured on the host.
But when I trying to use nslookup directly in container it failed to lookup but wget still success! What makes it different?
Reproduce steps:
docker network create my-net
docker run -d --name web --network my-net httpd
docker run -it --rm --network my-net busybox
after inside busybox:
$ wget -q -O - web
<html>...some content...</html>
It works great! but use nslookup will failed:
$ nslookup web
Server: 127.0.0.11
Address: 127.0.0.11:53
Non-authoritative answer:
*** Can't find web: No answer
This is my docker's version:
$ docker version
Client: Docker Engine - Community
Version: 20.10.21
API version: 1.41
Go version: go1.19.2
Git commit: baeda1f82a
Built: Tue Oct 25 17:53:02 2022
OS/Arch: darwin/amd64
Context: colima
Experimental: true
Server:
Engine:
Version: 20.10.18
API version: 1.41 (minimum version 1.12)
Go version: go1.18.6
Git commit: e42327a6d3c55ceda3bd5475be7aae6036d02db3
Built: Sun Sep 11 07:10:00 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: 5fd4c4d144137e991c4acebb2146ab1483a97925
docker-init:
Version: 0.19.0
GitCommit:
While reproducing your issue I noticed that nslookup failed for any query (e.g., nslookup google.com also failed. Afterwards, I tried spinning up an ubuntu container on the same network and there both wget and nslookup worked fine. I do not know the exact reason why this is so, but my guess is that wget and nslookup rely on some system functionalities which are different for busybox and for ubuntu.

Windows 10, Docker problem with Port 80, Ports are not available: listen tcp 0.0.0.0:80:

I was trying to run docker app...
λ docker run -p 80:80 -p 8080:8080 --name billingapp sotobotero/udemy-devops:0.0.1
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
I was trying to apply this answer...
https://stackoverflow.com/a/65274083/811293
λ netsh int ipv4 add excludedportrange protocol=tcp startport=80 numberofports=1
The process cannot access the file because it is being used by another process.
I was trying with https://stackoverflow.com/a/66198584/811293
D:\Programs\cmder\config\profile.d
λ docker container rm billingapp
billingapp
D:\Programs\cmder\config\profile.d
λ net stop winnat
The Windows NAT Driver service is not started.
More help is available by typing NET HELPMSG 3521.
D:\Programs\cmder\config\profile.d
λ docker run -p 80:80 -p 8080:8080 --name billingapp sotobotero/udemy-devops:0.0.1
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
D:\Programs\cmder\config\profile.d
λ
Checking with Resource Monitor...
Checking with netstat
D:\Programs\cmder\config\profile.d
λ netstat -aon | find /i "listening" | findStr ":80"
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:808 0.0.0.0:0 LISTENING 4140
TCP [::]:80 [::]:0 LISTENING 4
TCP [::]:808 [::]:0 LISTENING 4140
D:\Programs\cmder\config\profile.d
λ
Using tasklist
D:\Programs\cmder\config\profile.d
λ tasklist /FI "PID eq 4"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System 4 Services 0 144 K
D:\Programs\cmder\config\profile.d
λ
VERSION Docker Desktop:
PS C:\WINDOWS\system32> Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName,DisplayVersion | where {$_.DisplayName -like "Docker*"}
DisplayName DisplayVersion
----------- --------------
Docker Desktop 2.5.0.0
PS C:\WINDOWS\system32>
In other side:
D:\Programs\cmder\config\profile.d
λ docker --version
Docker version 19.03.13, build 4484c46d9d
D:\Programs\cmder\config\profile.d
λ docker version
Client: Docker Engine - Community
Cloud integration: 1.0.1
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:00:27 2020
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:07:04 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
D:\Programs\cmder\config\profile.d
What other solution I need try to apply?
I had the same problem, got rid of it with this command
NET stop HTTP
it stopped the print queue service ("Druckwarteschlange" in German).
Bad side effect, you can't use your printer anymore..

Metabase on docker not getting exposed

I'm having some trouble trying to get metabase running on docker.
I've installed Docker for Windows 7 following this tutotial.
Here is the docker version:
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24302
Built: Fri Mar 23 08:31:36 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.05.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.10.1
Git commit: f150324
Built: Wed May 9 22:20:42 2018
OS/Arch: linux/amd64
Experimental: false
Now when I try to get the metabase running on docker, using
docker run -d -p 3000:3000 --name metabase metabase/metabase
and using
docker logs -f metabase
I get the message after all the setup:
Metabase Initialization COMPLETE
The problem is when I try to access http://0.0.0.0:3000 I get a ERR_ADDRESS_INVALID. I looked for all the ports that are "LISTENING" using
netstat -aon | find /i "listening"
I don't see the 0.0.0.0:3000 listed there.
Docker ps returns:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a283cf6b8d7 metabase/metabase "/app/run_metabase.sh" 4 hours ago Up 4 hours 0.0.0.0:3000->3000/tcp metabase
I'm not sure if this is a problem with metabase image or with docker itself.
Does anyone have an idea on what this could be?
This 0.0.0.0 is not a valid IP address, but a non-routable meta-address
Your application is reachable on your machines IP address / hostname on port 3000.
If you are unsure, what your hostname is, you can run in powershell;
hostname
And then access it using http://your_hostname:3000

Error with Docker daemon for docker installation on Fiware cloud

I am new with the Fiware and docker technologies so I need some help.
I am following the instructions from this link http://simple-docker-hosting-on-fiware-cloud.readthedocs.io/en/v1.0/manuals/install in order to create a docker-host machine on Fiware cloud but when I run the following command:
docker-machine create -d openstack --openstack-flavor-id="2" --openstack-image-name="base_ubuntu_14.04" --openstack-net-name="node-int-net-01" --openstack-floatingip-pool="public-ext-net-01" --openstack-sec-groups="docker-sg" --openstack-ssh-user "ubuntu" docker-host
I receive the following error:
Error creating machine: Error running provisioning: Unable to verify the Docker daemon is listening: Maximum number of retries (10) exceeded
Although, I can see the instance of the docker-host machine on Fiware cloud, but when I run the following command:
eval "$(docker-machine env docker-host)"
the following error comes up:
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "147.27.60.136:2376": dial tcp 147.27.60.136:2376: connectex: No connection could be made because the target machine actively refused it.
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which might stop running containers.**
I also tried to regenerate the certificates:
docker-machine regenerate-certs docker-host
but I received the following error:
Error getting SSH command to check if the daemon is up: ssh command error:
command : sudo docker version
err : exit status 1
output : Client:
Version: 18.04.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 3d479c0
Built: Tue Apr 10 18:21:14 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?**
Image with the result for the Command: docker-machine ls
What am I doing wrong?
I use docker community edition for windows 10.
The docker version is:
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:06:28 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:14:32 2018
OS/Arch: linux/amd64
Experimental: false
First make sure you've opened your docker port (tcp/2376) in your default security group
Let me suggest you using base_ubuntu_16.04 instead of base_ubuntu_14.04
Anyway, it won't run properly at first. There is a problem with the latests versions of docker and docker-machine. As a workaround, after running your docker-machine command, you can do this to fix the problem:
ssh docker-host 'sudo apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual ; sudo modprobe aufs ; sudo service docker start'
However, you might find furhter problems due to MTU configuration in your docker host. To solve them, you can lower your MTU with these commands:
docker-machine ssh docker-host "sudo sed -i 's/--label provider=openstack/--label provider=openstack\n--mtu=1400/g' /etc/default/docker"
docker-machine ssh docker-host "sudo service docker restart"
docker-machine ssh docker-host "sudo ip link set mtu 1400 dev docker0"

Docker: coudn't expose a service

Couldn't manage simple task I did before many times (I've updated Docker few days ago if it matters and had a lot of errors with docker-compose which couldn't even give a version): run a container locally and access an exposed path. Simple, but I have an Error 61. Connection refused
What I do:
docker build container_name . -- in a Dockerfile I exposed both 80 and 5000
docker run -d -p 80:5000 container_name
Chech my docker-machine dev ip address on port 80 -- connection refused.
Inside the container I have a running gunicorn on port 5000. It works fine.
When I login to the container I could easily curl localhost:5000. And have a fine response from working server on localhost:5000.
So I need only map port 80 on my host to port 5000 inside the container, that's what the cmd -p 80:5000 should do, right? But it doesn't work. What do I do wrong?
docker version:
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.3
Git commit: a34a1d5
Built: Fri Nov 20 17:56:04 UTC 2015
OS/Arch: darwin/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.3
Git commit: a34a1d5
Built: Fri Nov 20 17:56:04 UTC 2015
OS/Arch: linux/amd64
Don't listen to localhost listen to 0.0.0.0 (or * depending on how the config does it)
localhost is specifically loop back within your container. To port map to host, you'll need to listen to a non-loopback address.
You don't need to EXPOSE if you're specifying -p though - that does it implicitly.

Resources