Docker Combat Guide
Docker Combat Guide
The Docker Guide for Software Developers
About the Book
First published : 2021-09-10
Current version: 2022-06-21 v.23
A 175 Full-size DIN-A4 size pages in PDF format, DRM-free, super effective for Developers in order to learn by examples how to use Docker (70% of the book) and Docker SDK for Python 3 (20%).
Docker allows you to run identical environment in Development that in Production.
Docker allows you to work with images that are equal in all you Servers, are immutable. If one works bad, you simply kill that Container and start another, new.
Docker is also very System Administrator, DevOps and SRE oriented, as it requires a lot of Linux understanding, so if you're a Software Developer you may not know how powerful it is.
This guide is created specifically for Software Developers in Python, PHP, Java, that want to discover the power of Docker Containers with easy examples.
It covers creating Docker in workstations running:
- Ubuntu Linux
- Windows
- Mac OS X
This is not an extensive guide for System Administrators, DevOps and SREs.
This is a guide for Developers that want to start using Docker super quickly, by using examples from different projects. Also explains the usage of docker-compose and the Volumes and bind mounts for persistance.
The guide offers source code and the link to a repository, so you can just clone the code from there.
Updates
2022-04-25 v.22
Explained differences between docker export and save.
Fixed a typo referring to docker ls instead of docker ps.
Show how to use docker logs.
2022-04-25 v.22
Updated Dockerfile for packages being updated and asking for interactive input.
Display how to install ping and ssh client and interact to Windows and Mac hosts from inside the Docker Container by using host.docker.internal.
2022-02-15 v.20
Added some tricks, like clearing the logs, using some tools, and using Docker in Windows from command line without activating Docker Desktop.
2022-01-20 v.19
Full Source code of the SDK sample Python 3 demo application uploaded to Extras.
2021-11-24 v.18
Added the usage of a Software to reverse engineering an image and getting the original Dockerfile.
Added a typical copy and paste error to Troubleshoot section.
Bundles that include this book
Table of Contents
- Index v.20 (2022-02-15)...........................................................................2
- Dedication.......................................................................5
- Contact me.......................................................................6
- Receiving Free Updates.............................................................6
- If you’re not satisfied..............................................................6
- Conventions......................................................................7
- Knowing what version are you using – docker version....................................8
- Creating our first Container..........................................................9
- Our first Dockerfile..............................................................9
- Running our first Container based in a Dockerfile.....................................10
- docker ps -a...................................................................10
- Running a Container that does something and exits......................................11
- Naming the images with -t (tagging)...............................................11
- docker images.................................................................12
- Running a container by its name..................................................14
- Have a cheap Ubuntu in your Windows or Mac with Docker...............................16
- docker ps.....................................................................21
- A simple web Hello World in Flask...................................................22
- A small CLI Python + MySql + Docker program as a sample..............................26
- Installing the MySql driver.......................................................27
- Dockerfile....................................................................28
- build_docker.sh................................................................29
- docker_run.sh.................................................................29
- docker_run_mysql.sh...........................................................30
- start.sql......................................................................31
- select_values_example.py.......................................................32
- Executing the Container.........................................................32
- Entering the Container and running the code.........................................34
- Tying together MySQL and a Python Menu with Object Oriented Programming.............34
- MySQL Library...............................................................35
- A Data Object: CarDO..........................................................36
- Queue Manager................................................................38
- Bonus.......................................................................44
- A Dockerfile with PHP, Apache and Catalonia Frameworks...............................45
- End of life of images............................................................46
- Create the Dockerfile...........................................................46
- The www.cataloniaframework.com.conf file.........................................49
- Stopping, starting the docker Service and creating the Catalonia image....................50
- Building with --no-cache option...................................................50
- Trying the Container working.....................................................51
- 2 / 178A base Dockerfile for your Jenkins deployments........................................53
- The EXPOSE instruction........................................................56
- Build the Container.............................................................56
- Run the Container displaying the password..........................................56
- Mapping the ports with -p........................................................57
- Configure Jenkins with Projects and Pipelines........................................60
- Why I propose you to use Python 3.8, at least, for your Internal Automation Tools in Docker
- Containers and Ubuntu LTS........................................................61
- Reliability and Maturity.........................................................61
- A sample Star Wars Python 3 Flask Applications........................................63
- MT Notation..................................................................67
- The Dockerfile for flask.........................................................67
- Installing PIP3 Requirements with pip3 install -r requirements.txt........................68
- Defining Environment Variables in the Container with ENV............................68
- File requirements.txt............................................................69
- build_docker.sh................................................................69
- Refreshing settings in a Docker immutable image with Python and Flask.....................70
- Smaller Images................................................................73
- Using Docker for Unit Testing......................................................74
- Using Docker for running a demo....................................................74
- Making a Container start automatically...............................................76
- Docker Volumes.................................................................77
- Launch a Container using a specific Volume.........................................78
- Docker compose.................................................................79
- Docker-compose with LAMP and PHPMyAdmin.......................................85
- Volumes.....................................................................88
- Exporting and Importing Docker Images..............................................89
- Docker container ls -a.............................................................90
- Cleaning what you don’t use: docker system prune......................................90
- DockerHub.....................................................................91
- Docker information...............................................................96
- Limit containers resources..........................................................97
- Limit the Memory of the Containers..................................................97
- Limit the CPU for the Containers....................................................97
- Adding an additional user, so you don’t have to run as root................................98
- Checking the logs from a Container.....................................................99
- Communicating with Docker Containers via Linux Signals and Python – docker kill...........99
- The Dockerfile...............................................................100
- The dockersignal.py file........................................................100
- build_and_run_docker.sh.......................................................101
- Tools and Tricks...................................................................103
- Reverse Engineering a Docker image to get the founding Dockerfile (dfimage)...............103
- Lazy Docker...................................................................107
- ctop..........................................................................109
- CTOP.py......................................................................110
- Using Docker in Windows 10 without Windows Desktop with Docker Engine and without WSL.111
- 3 / 178Installing Docker Command line binaries..........................................112
- Turn Windows features on or off.................................................113
- Enable Experimental Mode.....................................................114
- Switch Daemon...............................................................115
- Troubleshooting...................................................................117
- Troubleshooting a failing Docker Container...........................................117
- Solving the problem when running an Alpine Docker Container: standard_init_linux.go:190: exec
- user process caused “no such file or directory”.........................................117
- A typical copy and paste error......................................................119
- Running out of space.............................................................120
- Space taken from Images.......................................................120
- Space taken from logs..........................................................120
- Using the Docker SDK.............................................................124
- MT Notation...................................................................124
- Installing the requirements........................................................124
- The most basic examples..........................................................125
- Run a Container..............................................................125
- Run a Container in Background..................................................125
- Pull an Image................................................................125
- List the Containers............................................................126
- Videos........................................................................132
- Docker SDK from Python demo (7m 55secs).......................................132
- Docker-compose up demo (4m 10secs)............................................132
- Docker SDK Demo Python 3 program.................................................136
- Running the program.............................................................136
- Setting PyCharm................................................................137
- To Run the demo from command line.............................................142
- First look at the code...........................................................147
- List Containers (first version)......................................................149
- Run the Container ubuntu:latest with echo hello world (bonus)............................151
- Running a Container.............................................................152
- Reverse Engineering to get what I need..............................................156
- List of all Containers (pretty version)................................................159
- Stop a Container................................................................161
- Deleting all the stopped Containers..................................................165
- Finding the prune equivalent.......................................................166
- Writing a Dockerfile and running the Container........................................168
- The docker-compose project.......................................................174
- Recommended bibliography.........................................................178
- Official Docker Documentation....................................................178
- Python Docker SDK.............................................................178
- Books.........................................................................178
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,712,765writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Recipes for Decoupling
Matthias NobackWrite software that survives
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
CQRS by Example
Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary- Leverage your Software Architecture skills by learning everything about CQRS in detail with lots of examples
- Develop faster applications by applying CQRS and fostering Read Models and Projections
- Learn how to apply CQRS into a brownfield project from a pragmatic approach
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
The PowerShell Scripting and Toolmaking Book
Don Jones and Jeff HicksLearn the patterns, practices, and details of PowerShell Scripting and Toolmaking from the industry's two most recognized experts on the subject.
The C4 model for visualising software architecture
Simon BrownA guide to visualising your software architecture with the C4 model.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #6
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #8
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming...