Although Docker has a huge learning curve, it also has a rewarding goal. Once you understand the docker way, things which were previously a blocker to your development can be done surprisingly easily.
Your production environment becomes the same as your development environment, making deployments simple.
Keeping your dev machine clean of muliple language dependencies also becomes a reality.
Where your project files actually go. Docker containers are deisgned to have a short volatile life, a bit like RAM, but when it goes down, it can br brought straight back up again with minimal effort. So your actual project files should never live in the container itself, they need to be stored in the host system (the machine running Docker) or a special container designed specifically to store files. Your application container can access these files via a mount which links the project files to the container, automatically updating if any files are changed. For more info take a look at Docker Volumes.
Everything runs as a separate process. People seem to find this one hard to grasp, or maybe just hard to accept. Docker is built in as an SPA (Micro process) architecture. This means that every running process should have it's own container. Assume for a moment that you have a Python application using MySQL as a database and Redis as a broker for Celery tasks, a simple set up in Docker would be to have your Python app in one container, MySQL in another and Redis in another. Each container can communicate using their various ports which they expose.
A few commands hidden away in the extensive documentation which can be hard to find but your going to need them:
docker logs [container]
- Your new way of reading those crazy errors.
docker inspect [container]
- Returns a JSON representation of your containers details, you should do this on every container you run as a matter of practice and be familiar with everything in there, this could save you a lot of time!
docker ps -a
- The key point here to use the -a
option, which means "all" and will show you any container which have been run previously but have stopped for any reason, good way to see all running containers quickly.
docker exec -it [container] /bin/bash
- The quickest way to run commands directly on a container.
Logs sometimes fail. The docker logs
command will sometimes gets stuck returning nothing or just a single line, to get around it specify the --tail
option, which seems to force docker to return all the log lines asked for. Exmaple: docker logs --tail="500" [container]
, or for a running output docker logs --tail="500" -f [container]
.