-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support expanded syntax of ports in docker stack deploy
#30476
Support expanded syntax of ports in docker stack deploy
#30476
Conversation
Thanks for looking into this. Unfortunately I don't think this is the right approach. I agree we should support a "long form" syntax for this field, but I don't think it should be the csv format. The csv format is a compromise because of limitations on the CLI. For the Compose format we should use a mapping structure with keys and values: ports:
- mode: host
target: 80
published: 9005 I'm about to push a PR that does this for Another related issue is #29193 |
Thanks @dnephin for the insight and help. I will spend some time to try to get the new mapping structure working. Still trying to learn the mechanism of compose schema though I think I am close. |
@yongtang you might be interested in #30521 which is some cleanup of the compose loader, and https://github.com/dnephin/docker/tree/add-expanded-mount-format-to-stack-deploy which is the branch for expanded mount format (that I thought I would have finished last week). |
Thanks @dnephin and @thaJeztah for the help, and pointing me to #30521. Very useful to understand the work flow of compose schema. I will update the PR with the new mapping structure as discussed. |
f0a6048
to
6e7db22
Compare
docker stack deploy
docker stack deploy
6e7db22
to
3ab110f
Compare
@dnephin @thaJeztah @vdemeester The PR has been updated with the support for expanded port syntax. I only changed Compose schema for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design LGTM,
few comments
"target": {"type": "integer"}, | ||
"published": {"type": "integer"}, | ||
"protocol": {"type": "string"} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking name
should be a field as well. I'm not sure why it's not supported in the cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnephin The Name
is not used in the swarmkit as the moment. I added the name
to the field. It is not actively but we could add the usage in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I guess if it's not being used by swarmkit, we shouldn't add it. It's strange that it's in the API types if it's not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnephin The PR has been updated with name field removed. Please take a look.
cli/compose/loader/loader_test.go
Outdated
} | ||
|
||
assert.Equal(t, 1, len(config.Services)) | ||
assert.Equal(t, len(expected), len(config.Services[0].Ports)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this assertion. It's covered by the next line, and it'll be easier to see the failure if the error shows the full diff, instead of just x != y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Done.
{"type": "string"}, | ||
{ | ||
"type": "object", | ||
"properties": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably also have additionalProperties: false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dnephin. Done.
"protocol": {"type": "string"} | ||
} | ||
} | ||
], | ||
"format": "ports" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might need to move format: ports
into the type: number
, and type: string
cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dnephin. Done.
cli/compose/loader/loader.go
Outdated
} | ||
for _, vv := range v { | ||
ports = append(ports, vv) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do this as ports = append(ports, v...)
?
(same above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dnephin. There was an compilation error when appending directly:
cli/compose/loader/loader.go:502: cannot use v (type []"github.com/docker/docker/cli/compose/types".ServicePortConfig) as type []interface {} in append
Now the toServicePortConfigs(value string)
has be changed to return []interface{}
(instead of []types.ServicePortConfig
) so it is possible to append directly with the update.
3ab110f
to
3c833e4
Compare
Thanks @dnephin for the review. The PR has been updated. Please take a look and let me know if there are any additional issues. |
3c833e4
to
db200f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐸
@yongtang needs a rebase 😅
This commit adds expanded port syntax to Compose schema and types so that it is possible to have ``` ports: - mode: host target: 80 published: 9005 ``` Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit adds support for expanded ports in Compose loader, and add several unit tests for loading expanded port format. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
db200f6
to
f07a28a
Compare
Thanks @vdemeester The PR has been rebased. |
All green and two LGTMS |
@dnephin do the changes to the compose format have to be synced back to the docker-compose repository? Also could you help getting these changes into the docs? |
Yes, and I guess so. |
@johnstep if you have a second and if you haven't already, could you test this on Windows? @brandonroyal took a quick look and couldn't get it working. cc @icecrime |
@johnstep hey, @sixeyed tested this on Windows with 17.04 (master) server and client and it worked. @dnephin one funny thing we found (sorry if you already thought of this) is that the error message for pre 17.04 clients is really bad (this is using the compose file that @sixeyed posted above):
|
What's bad about that error message? It seems to provide the necessary information. It has the path to offending value, and the problem with the value. |
@dnephin it seems not good if the actual solution is "upgrade to Docker 17.04" |
…ntax Support expanded syntax of ports in `docker stack deploy`
Just a note for whoever reads this: Using the long port format requires |
hi, @sixeyed I have tried this below stack file but i can't connect from out side of the host. Can you please suggest me
Below is this Docker ps out put. I think its publishing to a different port
|
@karthick0070 that format is incorrect; either use the "shorthand" format (just version: "3.2"
services:
web:
image: iiswithdb
ports:
- mode: host
target: 8080
published: 8080
deploy:
replicas: 3 |
@thaJeztah Thanks for your help... it is working fine as excepted. |
I still has this program "services.web.ports.0 must be a string or number" when run this
how can I solve this program @friism @sixeyed @thaJeztah |
Same. I'm using Docker EE for Windows and Windows Docker Container using Windows Server 2016 LTSC, as far as I know there is no routing mesh support yet. Is it possible to use publish: 81, 82, 83 if your replicas is 3? |
- What I did
NOTE: The description has been updated based on #30476 (comment)
This fix tries to address the issue in #30447 where it was not possible to specify
mode=host
for ports in compose.- How I did it
This fix addresses the issue by adding support for expanded ports syntax:
- How to verify it
Several unit test has been added to cover the changes.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #30447.
This fix is related to #29961/#30103.
Signed-off-by: Yong Tang yong.tang.github@outlook.com