Comments (3)
Container
I added a default port 32768
for a docker container if no external port is given. Due to terraform
internals and tfstate
sync I could not achieve an empty port or a computed port which is the same as the internal one.
provider "docker" {
version = "1.0.2"
}
resource "docker_image" "centos-box" {
name = "centos:latest"
keep_locally = true
}
resource "docker_container" "app-server" {
name = "app-server"
image = "${docker_image.centos-box.latest}"
ports = [
{
internal = 8443
external = 8443
},
{
internal = 22
external = 22
},
]
}
and the corresponding state
{
"version": 3,
"terraform_version": "0.11.8",
"serial": 5,
"lineage": "4de1b64c-bdfb-f66a-a5b9-4fdf361e45b6",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {
"docker_container.app-server": {
"type": "docker_container",
"depends_on": [
"docker_image.centos-box"
],
"primary": {
"id": "033b6a8a57be32b788d33d9c5387bdd13f3e471a61aa52bdcbb69fc87b95c9d5",
"attributes": {
"bridge": "",
"gateway": "172.17.0.1",
"id": "033b6a8a57be32b788d33d9c5387bdd13f3e471a61aa52bdcbb69fc87b95c9d5",
"image": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6d",
"ip_address": "172.17.0.2",
"ip_prefix_length": "16",
"log_driver": "json-file",
"must_run": "true",
"name": "app-server",
"ports.#": "2",
"ports.1670854030.external": "8443",
"ports.1670854030.internal": "8443",
"ports.1670854030.ip": "",
"ports.1670854030.protocol": "tcp",
"ports.362530277.external": "22",
"ports.362530277.internal": "22",
"ports.362530277.ip": "",
"ports.362530277.protocol": "tcp",
"restart": "no"
},
"meta": {},
"tainted": false
},
"deposed": [],
"provider": "provider.docker"
},
"docker_image.centos-box": {
"type": "docker_image",
"depends_on": [],
"primary": {
"id": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6dcentos:latest",
"attributes": {
"id": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6dcentos:latest",
"keep_locally": "true",
"latest": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6d",
"name": "centos:latest"
},
"meta": {},
"tainted": false
},
"deposed": [],
"provider": "provider.docker"
}
},
"depends_on": []
}
]
}
Service
Nevertheless @laimVM, AFAICS you wanted to achieve to ramp up multiple containers of an image with the terraform-docker
version 0.1.1
which was pre #40. Now you should be able to achieve starting multiple replicas of a service via
resource "docker_service" "app-server" {
name = "app-server"
task_spec {
container_spec = {
image = "${docker_image.centos-box.latest}"
}
}
mode {
replicated {
replicas = 2
}
}
endpoint_spec {
ports = [
{
target_port = "8443"
published_port = "8443"
},
{
target_port = "80"
published_port = "80"
},
]
}
}
HTH Manu
from terraform-provider-docker.
So am I understanding this change correctly, before a random external port was assigned, but the tfstate didn't pick it up. Though now the external port is just assumed to be 32678
. This means I can't use the randomly assigned ports provided by docker, and must specify the external port in all cases?
from terraform-provider-docker.
This means I can't use the randomly assigned ports provided by docker, and must specify the external port in all cases?
Yes, atm it is like this. But let me find a solution with the core team how to handle it correctly. My first thought with Computed: true
from the docs and other approaches did not work. I'll track it in #102
from terraform-provider-docker.
Related Issues (20)
- ci: update to go 1.15 HOT 1
- Make docker_registry_image datasource independent of docker host endpoint HOT 4
- Missing security_opt option for docker_container resource
- How can I pass private_key for ssh connection? HOT 1
- Alias fails when passed to child module.
- Image value in docker_service state doesn't stick
- Image argument after v2.6.0 always replaces resources (mismatch between image name vs sha image id) HOT 2
- Modifying labels does not recreate container
- How to use provider with simple get from https://hub.docker.com/search?q=&type=image HOT 1
- [docker_network] - check_duplicate not working
- Unable to remove Docker image: image is referenced in multiple repositories HOT 1
- Swarm Secret Data Source
- Provider can't connect to Docker daemon in WSL 2
- Crash Import service docker module with hosts include
- Call for future maintainers HOT 8
- Add support for docker plugins
- terraform destroy does not respect stop_grace_period for docker swarm services running on DOCKER_HOST
- OCI images are not supported
- Null user should not force a replacement
- Non existent or null workdir should not force replacement
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-docker.