Docker deploy error port is already allocated

Did you get this working again, @Hyperbytes?

I run into some issues trying to deploy to a DigitalOcean Droplet from two different machines.

So the setup is like so: I have W10 machine that I use mostly for Wappler dev work. This pushes a Wappler test project to my DO droplet just fine. However, I’d like to be able to deploy from my Macbook Pro, as well. To do some dev work on the road.

I use the Wappler github integration to make sure I have all the files on my MBP. I exported on the w10 machine and imported the docker machine keys ont the mac with this tool:
https://medium.com/@cweinberger/docker-machine-export-and-import-34ae2899e9d7

I did notice that in the target folder on the mac, the db_init folder was missing. I added that manually.

Now when I try to deploy to the local docker from the mac, it works fine. However, trying to deploy to the droplet I get an error:

Building web
Sending build context to Docker daemon  7.014MB
Step 1/4 : FROM wapplerio/node-12
 ---> 7f4100422308
Step 2/4 : COPY ./ /opt/node_app/
 ---> Using cache
 ---> e7db6f2a6ba8
Step 3/4 : WORKDIR /opt/node_app
 ---> Using cache
 ---> 5973c27ad359
Step 4/4 : RUN npm install --no-optional --production
 ---> Using cache
 ---> a208818dfbae
Successfully built a208818dfbae
Successfully tagged do_test_102__staging_web:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Recreating 0834eaa828d9_do_test_102__staging_db_1 ... 
Recreating 0834eaa828d9_do_test_102__staging_db_1 ... error

ERROR: for 0834eaa828d9_do_test_102__staging_db_1  Cannot start service db: driver failed programming external connectivity on endpoint do_test_102__staging_db_1 (0d1d8eaf5691b877f3e65ac8100f6bec65757a5683b76b9aa228bae86444b6cd): Bind for 0.0.0.0:9906 failed: port is already allocated

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint do_test_102__staging_db_1 (0d1d8eaf5691b877f3e65ac8100f6bec65757a5683b76b9aa228bae86444b6cd): Bind for 0.0.0.0:9906 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
Error Launching Services!

Does anyone have any advice on how to access a DO droplet for deployment from two different machines?

Thanks in advance for anyone willing to chime in. :+1: :grin:

This a common issue on windows when the port stays open for longer than it should. You can just try to redeploy or if the problem persist - restart your pc.

I will move this to a new topic as it is not really related to the current one.

Thanks for splitting up the topic, even during the summer break!

I see your point about this issue being common on windows machines. However, this is on trying to deploy to a DO droplet from a mac running latest mac os.

I have tried multiple restarts, with no results.

Any other suggestions as to what this could be?

@jellederijke
I get this quite a bit on OSX too, so not just a common issue on Windows as @George suggests.

I think I uncheck Install Portainer and Traefik, redeployed to DO and then checked them again and deployed. It’s worth a try.

No this is a different issue because it is about tge database port 9906

Portainer is about port 80

Are you sure you have selected the remote DO target?

It might be a different project that is already running on the same droplet? Or did you rename the project?

Deploying on the local target gives no issues. Deploying on the windows 10 machine to the DO droplet doesn’t give any issues, either.

It only happens deploying to DO droplet from mac OS. Funny thing is that testing connection to the remote target results in no apparent issues:

Testing Docker Connection ...
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  compose: Docker Compose (Docker Inc., v2.0.0-beta.6)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 4
  Running: 2
  Paused: 0
  Stopped: 2
 Images: 23
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2
 runc version: v1.0.0-0-g84113ee
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-144-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 985.1MiB
 Name: drop2
 ID: FF5Z:R46W:3OXP:ROMZ:W7EL:7BOX:LTBT:ZJZS:PBGI:72DD:64HS:P72O
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
  provider=digitalocean
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support
Docker Connection Successful!

This are the settings for the remote docker:

So first I had an issue with the certificates folder not existing. I fixed this thanks to your post with the machine export import tool.

The project is nothing fancy, either. Just a test project with some default pages, some added fields to the user table and a security provider for login etc.

http://188.166.40.91/main_test

Otherwise, the docker implementation feels pretty solid and muuuuuuch easier to publish a project on a droplet than I imagined it to be! :grin:

Good to hear!

Are you deploying exactly the same project one time from windows and another time from Mac?

And you just backup and restore the docker machine config?

If you have installed also portainer on the DO droplet, you might want to check all the docker containers running with it.

Yes, exactly the same project. Synced through wapplers github integration from the w10 machine to the mac.

And in order to connect with the remote target I used the import export machines tool, as described.

I haven’t touched upon the portainer subject, yet. So I am not running that. This was my first attempt at docker icw hosting.

I can even share the git, if that helps. It contains no sensitive info.

Well I haven’t really tried to share the exact same project between windows and Mac. There might be some naming convention issues resulting in different container names.

That is why I asked if you can list the running containers.

You can do that by making sure you have selected the DO target, then choose to open an SSH terminal from the terminals menu below, and then run:

docker ps

Let me know what the output is.

System information as of Mon Jul 26 19:44:18 UTC 2021

  System load:                    0.0
  Usage of /:                     12.7% of 24.06GB
  Memory usage:                   64%
  Swap usage:                     0%
  Processes:                      96
  Users logged in:                0
  IP address for eth0:            188.166.40.91
  IP address for eth1:            10.110.0.3
  IP address for docker0:         172.17.0.1
  IP address for br-4b479cb4c8a1: 172.18.0.1
  IP address for br-77bcf18e2be2: 172.19.0.1

15 updates can be applied immediately.
To see these additional updates run: apt list --upgradable


*** System restart required ***
root@drop2:~# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                 NAMES
18244cf2f6e9        do_test__staging_web   "docker-entrypoint.s…"   6 hours ago         Up 6 hours          9229-9230/tcp, 0.0.0.0:80->3000/tcp   do_test__staging_web_1
01de7f387f9a        do_test__staging_db    "docker-entrypoint.s…"   6 hours ago         Up 6 hours          33060/tcp, 0.0.0.0:9906->3306/tcp     do_test__staging_db_1

This is the output from the Mac, btw. Or did you mean the W10 output, as well?

Are you sure you are deploying the same project?

As it is now called “do test”

But before it was “do test 102”

The project name should be really exactly the same…

Hi George, I am stuck with this problem too. I have redeployed, restarted the pc multiple times, wait one day. And the problem persists. I keep on having the same error:

If you have the same problem execute also the docker ps command as asked above.

The docker ps command is not working for me:

Best.

Jay

Try to prefix the command with sudo, like:

sudo docker ps

Thanks George,

OK, now I got a report back.


What should I do now? do I remove the container c09… so that it makes the port 9906 available again? Will I loose the database info in the container?

Sorry, but I am not a Docker expert, I really need some handholding here.

Best.

Jay

Well I see your development target running there.

Are you sure you are on the remote target? Did you do some targets settings and name change after initial deploy?

From the docker ps output, there is a container which is listening on port 9906 as you can see under the ports column.

You can kill this container with docker kill container . At which point it will free up the port. In your case:

sudo docker kill c09….
1 Like

This fixed it for me! I stopped both running containers and now everything is perfect :grin: :partying_face:

Thanks for the awesome support, George.

1 Like