We are creating a new product and it’s strategic for us to deploy it using Docker. The first option was to use AWS Elastic Beanstalk, choosing the option to deploy dockers. The deploy works perfectly. The problem is the re-deploy.
We don’t know the root cause but sometimes when we re-deploy a container we get this error:
Stop the container before attempting removal or force remove
We think that this is an AWS problem due to 2 reasons:
- Sometimes the re-deploy works perfectly
- I should not care about stopping a container. This is an AWS problem 🙂
We even tried StackOverflow to solve this problem, but no answers until now.
One of the tries was to deploy a temporary container before deploying the final container. So instead of doing this:
Our product (version 1.0) →Our product (version 2.0)
We tried to do this
Our product (version 1.0)→Maintenance Docker→Our product (version 2.0)
But this doesn’t solve the problem also. At least this led us to release a generic Maintenance Docker image, to help anyone else that want to deploy a temporary page or just undeploy something.
We also tried AWS ECS and Fargate, but both seem to complex to our needs. So we started again with a basic EC2 machine. In few minutes our problem was solved! Our final solution is:
- GoDaddy: to buy a new DNS name
- AWS Elastic IP: we reserved a public fixed IP for us. This means that this number will be “always” from TeraHorse.
- Private IP: we have a private IP inside our VPC at AWS that points to our EC2 instance
- AWS EC2 Instance: finally our server!
So, the main idea is:
DNS name → public IP → private IP → EC2 instance
Now, to update our Docker container we just run a shell like this (actually it’s encapsulated by a Gradle task, but this doesn’t matter)
ssh -i ~/myPrivateKey.pem email@example.com -C 'sudo docker stop myContainer'
Actually, in this “-C” parameter we pass all necessary commands to redeploy a container: docker stop, docker rm, docker rmi and docker run.
So to summarize our opinion: AWS Elastic Beanstalk can be great to quickly deploy a product or to do a Proof of Concept. But sometimes the excess of layers and abstractions can make you be less productive. Think about it 😉