Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Create container with port forwarding #7

Merged
merged 6 commits into from
Feb 21, 2023

Conversation

jackgene
Copy link

@jackgene jackgene commented Feb 20, 2023

This PR resolves #8 by adding the ability to create containers with port forwarding. The changes are non-breaking:

  1. DockerClient#createContainer(...) updated to take a third portBindings parameter that is an array of PortBindings (defaulting to empty array - no port forwarding). (See doc comment for details) of PortBinding.
  2. DockerClient#start(...) updated to return an array of PortBindings -indicating the the actual port bindings. This is mainly for use cases where the client makes a request to forward to a random available host port (hostPort=0), such that the client is able to get the actual bound port. If the requested hostPort is non-0, the return value should just be what the client provided.

Changes were made to the Docker JSON model to support this.

@alexsteinerde
Copy link
Owner

Thanks for the PR.
I'll look into this.
By the way the following fork of this repository implemented a lot more functionality. Maybe you want to check it out as well:
https://github.com/m-barthelemy/DockerSwift

@alexsteinerde alexsteinerde merged commit 58d0a76 into alexsteinerde:main Feb 21, 2023
@alexsteinerde
Copy link
Owner

I just noticed, that this doesn't compile under Linux because the Network framework isn't available there.
Is there a reason to use typed IPv4 and IPv6 addresses there?

@jackgene
Copy link
Author

I just noticed, that this doesn't compile under Linux because the Network framework isn't available there. Is there a reason to use typed IPv4 and IPv6 addresses there?

My main reason for using typed addresses (vs just strings) is to try and make it harder for client codes to make mistakes (by passing in arbitrary strings, for instance). I had not considered Linux support, but would like to support it.

Do you happen to know if there are Swift typed IP address implementations other than what's in Network? If not, we can just use strings. I quickly looked through SwiftNIO and didn't find anything.

@alexsteinerde
Copy link
Owner

I didn't find a typed IP implementation as well. There is the SocketAddress type but that also holds the port and is a too heavy type for this problem in my opinion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for port forwarding
2 participants