I currently have a locally tested and working web app that consists of 4 docker containers: Java MVC, NodeJS, Flask, and MongoDB. I have 4 Dockerfiles, one for each, and I manage the builds with docker-compose.yml.
However, now I want to push my code to Heroku and I read the documentation at https://devcenter.heroku.com/articles/container-registry-and-runtime. However, it seems very ambigious about how to use docker-compose on the production line. This is what it says on the docs:
"If you’ve created a multi-container application you can use Docker Compose to define your local development environment. Learn how to use Docker Compose for local development."
Can anyone guide me to some actual code of how I can push my project to the Heroku Container using Heroku's CLI?
Just an update on this question since it seems to be getting a lot of traction lately.
There is now an officially supported "Heroku.yml" solution offered by Heroku.
You can now write a .yml file (with a format similar to docker-compose) and Heroku will work out your images. Just follow the link above for details.
Happy Heroku-ing.
The more accurate heroku documentation for what you are looking to do is here:
https://devcenter.heroku.com/articles/container-registry-and-runtime
The above will walk you through setting up the heroku container plugin and logging into the registry. You can even migrate an image to a Dockerfile with the following line in your dockerfile:
FROM "<insert Dockerfile tag here>"
To easily set this up, you will name your Dockerfiles with different suffixes, such as Dockerfile.mongo, Dockerfile.node, Dockerfile.flask, and Dockerfile.javamvc. The suffix tells heroku the dyno name used for your web app. When you need to push all of your containers, you can do so with the following command, which will recursively build all dockerfiles as long as all of them have unique suffixes:
heroku container:push --recursive
As Heroku doesn't read docker-compose files, any environment variable setup/port exposure/etc will need to be migrated to the Dockerfile. Also as I can't find how to do persistent storage/volume mounting with containers on Heroku, I would recommend using a Heroku add-on for your mongo database.
On Heroku, you will see your app running as one dyno per Dockerfile, with each dyno's name as the suffix of each Dockerfile.
UPDATE:
Travis brings up a good point. Make sure to have a CMD statement in your Dockerfile, otherwise heroku will throw an error.
Heroku recently added a step to the process, you will need to run heroku container:release <your dyno name> for each dyno that you want to update.
Yet another update on this question, as I was looking into it and found out that Heroku now officially supports docker-compose.
Please follow this guide: Local Development with Docker Compose
Worth noting that, as Heroku is non-persistent, the guide above recommends you to use official docker images of (redis, postgres, etc.) for local development, but use Heroku's offerings when deploying on it.
Related
my crawler work on AWS EC2. but when i want to make it run, everytime i have to run EC2, then i have to write cd FileName and sudo docker-compose up -d.
it make me so tired.
i hope something can work instead of me, after i search about ECS
but there is really lots of data and i can't filter what is accurate information for me.
if you don't mind can you recommend the links what i can solve this issue !
You can use ECS which is available in two favors
Serverless (Fargate) where you don't have to manage anything except your docker compose file and second is to use EC2 as launch type for ECS.
Docker and AWS have been collaborating and now there is an in built support for docker compose files since . Please refer to official docs
https://aws.amazon.com/blogs/containers/deploy-applications-on-amazon-ecs-using-docker-compose/
https://www.docker.com/blog/docker-compose-for-amazon-ecs-now-available/
I created a web app and hosted it on Heroku a while ago. I basically wrote a dockerfile with all the instructions and followed steps like here. I just now opened my old laptop and made changes to some of the code. I tried to follow the same steps as usual to push changes, but when I run heroku container:push web -a bluebird-teaching (the app is called bluebird-teaching), I get a strange error.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I made sure that I'm logged in on Heroku CLI and my app still runs. The name of the app on Heroku is indeed the same name I'm putting in the tag (not sure of that matters). I can't just do heroku create because that's going to create a whole new app. I would just like to push changes to an existing app. Any ideas how I could do what I'm trying to do?
Thanks for any help.
Docker is not running on your old laptop.
The heroku container:push builds and pushes the image as defined in the Dockerfile: this needs the Docker deamon to run.
Screenshot: my docker-compose for wordpress
I've learned last week how to deploy 3 containers of wordpress, phpmyadmin and mysql. They work fine. The containers were connected between them, using a volume and the same network. The docker was configured from a docker compose file. .yml I used Git of my native operative system to version the changes.
But then I found another way to do the same:
I installed a image of Debian, then added git, apache2, mariadb and phpmyadmin, i connected all and use a "docker commit" to save changes of my development every time.
Then, a coworker told me to use a docker-file and add volumes an use Git for versioning.
Which is the best way?
What problems have the first and second ways?
Is there another way?
From my view you search for optimal deployment structure, its a long way to go and find information about. Here my opinons:
I wouldn't recommend this version because the mix of operation system (win/linux) can cause big problems. Example, Line Breaks, Folder/File Filename.
But the docker compose idea is the right way to setup the test, dev enviroment local.
is outside of git, thats not optimal, but a good solution when save everything.
is alright, but you done already with docker compose. Here the usage of volume can cause same problems as 1. You can use git versioning in commandline mode to develop, but I don't recommend it.
Alternative Ways
Use Software that able to deploy remotely to the php server, like PHPStorm, Eclipse, Winscp use local to develop the application and link it to the Apache/PHP Maschine or Container over FTP/SFTP. You work local and transfer the changed files into the running maschine or container. The Git Versioning would be done on the local maschine. You can also use mysql tools to backup the database local. So if the docker container brake you can setup it easy again.
Make sure you save also config files of apache, php, mysql into git, that makes the resetup of docker container smart.
Use (Gitlab & Gitlab CI), (Bitbucket & Bamboo), (Git & Jenkins) to deploy your php changes to the servers or docker containers.
At best read articles over continuous delivery and continuous integration.
This option is suitable for rollout to customer or dev, beta systems.
I build a RoR app on Heroku that must be run inside a Docker container. To do so I use the official Dockerfile. As it is very common with Heroku, I need a few add-ons to make this app fully operational. In production the variable DATABASE_URL is available within my app. But if I try some other add-ons that use environment variables (Mailtrap in my case), variables aren't copied into the instance during runtime.
So my question is simple: how can I make docker instances aware of the environment variables when executed on Heroku?
As you may ask, I already know that we can specified an environment directive right in docker-compose.yml. I would like to avoid that in order to be able to share this file through the project repository.
I didn't find any documentation about it but t appears that Heroku change very recently the way it handles config vars in Docker containers: they are now replicated automatically (values from docker-compose.yml are simply ignored).
The workaround to not commit sensitive config files, would be to create a docker-compose.yml**.example** with empty fields and commit it, then add docker-compose.yml to .gitignore.
Since that's not very practical on heroku, you can use the --env docker switch to add any variable to the container's environment.
Like this: docker run --env "MY_VAR=yolo" my_image:my_tag
You could also serve a private docker-config.yml from a secure site, that heroku would have access to (that would be my preferred solution in your case).
I want to use Docker to deploy my Rails application. I want to know if there is someone tried this? And what problems can I face?
Deploying Rails apps to production with Docker is not only possible, but something you'd want to do, to make sure your app runs on any server you deploy.
This comes with some challenges. First, it's advisable to run your database server and your Rails app different containers to keep things isolated. You can also set up your production server Docker environment with Docker Machine. Machine allows you to configure AWS, Digital Ocean, Azure and Compute Engine instances (among many others), and manage your containers from your computer. I assume you're just getting started with Docker, so I suggest you take a look at this cool guide about setting up a Rails + Postgres app with Docker.