The Docker provider is used to interact with Docker containers and images. It uses the Docker API to manage the lifecycle of Docker containers. Because the Docker provider uses the Docker API, it is immediately compatible not only with single server Docker but Swarm and any additional Docker-compatible API hosts. read more here
First you need to initialize terraform.
terraform init
now its time to actually using apply.
terraform apply
NOTE: to verify these two components one by one if they are created successfully using terraform with docker provider, run:
docker image # Verify docker image
docker ps -a # Verify docker container
execute some long running commands to ensure my ubuntu image doesn't finish immediately.
also must_run = true
trying to keep container running. If false, then as long as the container exists, Terraform assumes it is successful.
- Create docker image
- Create docker container
- Create docker service