I have not used or seen docker-compose used with CDK, but CDK would be for defining the infrastructure on AWS and docker-compose for running the stack locally I imagine, not using compose with CDK.
You reference a Dockerfile in your CDK setup and CDK builds it for you and pushes it to ECR. The ECR repo is set up by CDK when running ``. So that handles that part for you behind the scenes. Quite convenient!
When you define CDK code that references a Dockerfile, you then pass the referenced image of the created ECR image to a task definition, for example, that then uses the image in AWS when deployed. Same can be done using lambdas also.
I hope this example below clears it up a bit. You could then for example use a pipeline like github actions or circleci to create a job that runs CDK deploy for you.
// This pushes it to ECR after building the file
const dockerImage = new DockerImageAsset(this, 'some-image', {
directory: path.join(__dirname, '../../')
})
this.loadBalancer = new ApplicationLoadBalancedFargateService(this, `${namePrefix}-lb`, {
cluster,
serviceName: `${namePrefix}-lb`,
taskImageOptions: {
containerName: `${namePrefix}-task`,
image: ecs.ContainerImage.fromDockerImageAsset(dockerImage), <-- this is where you pass the docker image reference
environment: containerEnvs,
containerPort: parseInt(containerEnvs.PORT),
enableLogging: true,
taskRole: role,
},
})