Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris
This article is part of a series:
Docker - from the begi...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you so much for sharing your valuable knowledge. This is such a gem!!!
glad to hear it
Hi, tks for these articles. They are very helpful.
Running the example from your repo (github.com/softchris/docker-compos...) I had a problem when I tried to start the containers.
When I run the code the way it is, I got the following error in the console (I increased the default timeout. Thought maybe it would be the problem):
wait-for-it.sh: timeout occurred after waiting 60 seconds for db:8000
When I update the compose file to use the container db port instead of the one mapped in the host, it works:
wait-for-it.sh: db:3306 is available after 7 seconds
I think, it kinda makes sense because one container will be talking to the other one without using the host (maybe?)
Sorry if you explained/fixed this and I missed the piece.
tks a lot.
I ran into same timeout issue as Thiago on Windows host and solved it by updating the internal DB port as instructed.
However, then I stumbled upon following issue on the product-service container:
Few hours of head scratching and unhealthy debugging later, the culprit turned out to be bind mount wiping out the node_modules directory. Got a workaround with this solution.
Better late than never!
thank you for lettting me know. I'm sure someone else will scratch their head here and see your comment
hi Thiago.
Thanks for writing this. I'm trying to understand what kind of OS you are on, linux, mac, windows? Just trying to rule out if it is OS dependent or not?
Hi Cris
I'm using Ubuntu 18.04.2 LTS and Docker (Client and Host) 18.03.1-ce
Thank you.
WOW! Excellent guide indeed.
I got a bit lost in the last step. What does the "ADD init.sql /docker-entrypoint-initdb.d" really do (just copying the file?) and how come mysql knows it has to run it? Or is it something programmed in the mysql:5.6 image? and how does it auths to the db?
The other question I wanted to ask, is how would you combine all this with a git repo in order to trigger automated tests and, if everything goes ok, automatic deploy?
Thanks for that :)
From hub.docker.com/_/mysql
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d
if I understand your question correctly that's a whole chapter in the official Docker documentation, docs.docker.com/docker-hub/builds/
THIS IS AMAZING!
Thank you SO MUCH!
Now I have an urgent need to refactor mi monolithic API into microservices with Docker 😄
That was the effect I was hoping for :) Good to hear you are finding it useful :)
Brilliant series of articles.I have recommended it to all my colleagues. Thanks very much.
happy to hear that it helps someone. Thank you :)
On a broader subject. Do u think in the future will devs have to worry about setting up docker or k8s etc or rather just leverage a PaaS such as cloud foundry? I like dev but not ops :)
That's a good question. Cloud is becoming more of a default. Tools will become better. It will be easier to do these things. There will be more services with a one click and you are in the cloud or just knobs and levers to pull to scale your app up and down. With that said there will always be a need to build these tools, question is it that falls into the laps of normal devs... DevOps is a very strong movement at the moment and understanding dev + devops imo makes you more into an architect
Thanks for the info and your time. I believe the whole ops side of devops will die off in 3-5 years as the tooling, PaaS (e.g cloud foundry) etc make it easier to any ops required and we will just e back to dev again :) lets wait and see. There might be a topic for a blog in our mini discussion :)
From:
conn.on('error', function(err) {
if(err) {
console.log('shit happened :)');
connect()
}
})
To:
con.on('error', function(err) {
if(err) {
console.log('shit happened :)');
connect()
}
})
one 'n' need to Exclude
Thank you for posting this series.
My biggest question: How do you deploy a docker-compose setup?
It seems like I only see people using compose for development.
Here's an example of that xhttps://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-multi-container
attempting to connect to DB time: 1
Example app listening on port 3000!
Error { Error: connect ECONNREFUSED 192.168.0.3:3306
at TCPConnectWrap.afterConnect as oncomplete
--------------------
at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
at connect (/app/app.js:27:7)
at Object. (/app/app.js:45:1)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.0.3',
port: 3306,
fatal: true }
I get this error
Great series of articles. It really helps to write everything down as you learn. You will learn it better and you can help others to learn from your mistakes. I hope you will continue to learn us as you learn more.
Hey Chris, thank your for the whole serie!!
Just a little detail to avoid errors for new readers, in the Turn your current directory into a Volume section, instead of
version: 3
in thedocker-compose.yaml
, needs to be at least version 3.2 as you have in the repository file.Again, thanks for the pretty well explained serie of posts!
hi Lionel. Thanks for reaching out. Really appreciate your comment. I'll make sure to update
Great article!, and thanks for that.
But, as in first 3 articles you used single/same example and that was very easy to understand. In article number 4 and 5 you used unrelated examples to first 3. If you had used the same example, it would have been great.
Also, can you add articles for continuous integration and deployment of docker containers?
Thanks, again!
Thanks for this excellent and well written walk through of Docker, it's helped me out quite a bit with a personal project I'm working on.
A couple important things that I didn't quite catch from this post relating to how the database container communicates to the service container that I think are worth calling out:
When you reference your database from your app service, the database host name is the same as the database service in the docker-compose.yml In your example this is "db". This seems obvious now but wasn't apparent to me at first.
For other database systems such as PostgreSQL where you need to specify the port number in the connection, the port to use is the container port, not the host port that it's mapped to. Using your example this would be 3306 not 8002.
For my use case I'm using PostgreSQL and the node-postgres library, so it's slightly different than MySQL, but I imagine others may run into this as well!
Thank you for this whole series!
Thanks Alex :)
Thanks
Hi Mauricio, glad it's helpful :)
Thanks for this series. I learned few things about a thing called Docker.
@softchris hi chris I really liked this article. quick question though. Should we still use compose or stack? thank you. :)
If I understand correctly Stack are used with Docker Swarm.. so for me your question becomes more should I use Docker Swarm or Kubernetes as an orchestrator? Both solve the job, I would go Kubernetes, it's more known, though but take that with a grain of salt. I need to deep dive more in Docker Swarm and Kubernetes