Consider an improved way of referencing containers in cloud.Service
See original GitHub issueThis is not a priority, but I wanted to capture this idea.
Consider this code:
let redisPort = 6379;
let redisCache = new cloud.Service("voting-app-cache", {
containers: {
redis: {
// <snip>
ports: [{ port: redisPort }]
},
},
});
let frontend = new cloud.Service("voting-app-frontend", {
containers: {
votingAppFrontend: {
// <snip>
environment: {
// using a string to reference the "redis" container
// is there a better way to reference the port?
"REDIS": redisCache.getEndpoint("redis", redisPort).then(e => e.hostname)
}
},
},
});
To reference the redis container from the frontend.votingAppFrontend container, I have to use the string value redis. It’s also annoying that I have to pass in the port, though I realize it will default to the first open port. I saw that ports are not named in Docker Compose, so that might be a hard thing to change.
At first glance, I’m not sure how we would make the types stronger (looks like dependent types), but perhaps there’s a way.
Other than promises, this is really the only flaw of an otherwise lovely program.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Best practices for building containers | Cloud Architecture Center
This article describes a set of best practices for building containers. These practices cover a wide range of goals, from shortening the ...
Read more >11 Leading Practices When Implementing a Container Strategy
Containers provide a manageable means to quickly redeploy a service in a specific configuration, replacing infrastructure with code.
Read more >Introduction to Docker quiz - TheServerSide.com
This 10-question Docker quiz will let you know if you're ready to move beyond the basics and expand your knowledge of container-related topics ......
Read more >Serverless computing vs. containers | How to choose
Serverless architecture and containers offer some similar benefits but differ in several crucial ways. Learn how to compare serverless computing vs.
Read more >What is a container? | Microsoft Azure
Containers address this problem by providing a lightweight, immutable infrastructure for application packaging and deployment. An application or service, its ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Here’s a thought - we could split the containers part of the arguments to Service into a separate parameter from the other options (which are often not needed) and then offer two overloads:
The later would be the “simple” model, and would name the container the same as the name provided to the
Serviceconstructor.Donna’s example would look like:
This also makes the multi-container case more pleasent as you don’t need to say the word “containers” for something that will always be there.
I would think we want to show the simple use case. I suspect many (most) services will just have a single container and single exposed port. This is something that’s bugged me with our current APIs, btw, since the “single container” case entails some extra concepts that may not make sense. (“What, I just wanted to run a single container, why would I have an array of them?”)