Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Easiest way to find an available network port for docker containers?

Featured Replies

What is the easiest way to find an available network port for a docker container?

I have a lot of docker containers, and it's not easy to determine what network ports are available. I also use docker compose for some, and it doesn't have a "docker allocations" option.

To answer your question first, there's really no "easy" way to do this, but here are a few commands that can be useful. If you want to never think about port mapping again, scroll down to my last option.

This command will list all containers and their exposed ports:

docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a

And to find an available port, the easiest way is to run the same command and just grep for the port to see if it's in use or not. Say you want to install a container that use port 8080 by default, then you run this:

docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a | grep 8080

If it returns an empty result, the port is available, but if it returns a container name and port, you know it's in use. So you run the same command again and just put a random port like 5035 to check if it's available, and if it is, you use that in your port mapping.

OR ( the "right" and more secure way to do it)

You can change all your containers' network to a custom network like br0 and assign each container its own IP. Then the port mapping is irrelevant, as the containers expose all ports, and since it's using a dedicated IP, there will be no port conflicts. The best way is to use a macvlan network for this; you can change this in Settings -> Docker (you might have to toggle the advanced view button. After you have done this, you have to set the network type for each container to custom br0 or create your own custom network. Then, under "Fixed IP" set an IP that is outside your router's DHCP range. Then you're done.

One thing you should know tho, is that by default containers on a custom network can NOT talk to containers that use the host or bridge network (unless you enable host access to the custom network in Settings-Docker). This is for security reasons, and you should only enable it if you need to. The only thing you need to worry about when deploying your containers now is to set an available IP instead of port, which is far easier IMHO. And if you sort all your containers by IP (like I do), it takes 1 second to see what the next IP you should use is. No more worrying about ports; you simply use the default port set by the container.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.