Docker Combat Guide
Docker Combat Guide
The Docker Guide for Software Developers
About the Book
First published : 2021-09-10
Current version: 2022-07-27 v.29
A 197 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. Although most of the examples use Python.
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 persistence.
The guide offers source code and the link to a repository, so you can just clone the code from there.
Updates
2022-07-29 v.27
- Automatically restart the Containers
- Added a Docker Container example with RabbitMQ and Python using it with package pika
2022-07-25 v.25
- Show how to install Jenkins with plugin Blue Ocean for Pipelines and persistent Volumes
- Show usage of USER command in Dockerfile
- Explaining WORKDIR
- Explaining ARG
- Explaining ENV
- Overriding ENV variables from Command Line
- Overriding or setting ENV variables from Command Line using a file and the argument
--env-file
2022-07-03 v.24
How to use different users in Dockerfile and in Interactive Sessions.
Showing how to run a jenkins containerized.
2022-06-21 v.23
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
- Table of Contents
- Index v. 25.......................................................................2
- Dedication.......................................................................6
- Contact me.......................................................................7
- Receiving Free Updates.............................................................7
- If you’re not satisfied..............................................................7
- Conventions......................................................................8
- Knowing what version are you using – docker version....................................9
- Creating our first Container.........................................................10
- Our first Dockerfile.............................................................10
- Running our first Container based in a Dockerfile.....................................11
- docker ps -a...................................................................11
- Running a Container that does something and exits......................................12
- Naming the images with -t (tagging)...............................................12
- docker images.................................................................13
- Running a container by its name..................................................15
- Have a cheap Ubuntu in your Windows or Mac with Docker...............................17
- What you do if you get stuck in a message asking for choosing a geographic tzdata region?....22
- Dockerfile directive ARG........................................................23
- Dockerfile directive ENV........................................................23
- Setting and ENV value from an ARG value in the Dockerfile............................24
- Overriding ENV variables from Command Line......................................24
- Overriding or setting ENV variables from Command Line with a file and argument --env-file..25
- docker ps.....................................................................27
- Connecting to the Host from a Docker Container........................................28
- Connecting to a Windows/Mac Host from a Docker Container as if it was localhost............29
- A simple web Hello World in Flask...................................................32
- WORKDIR...................................................................35
- A small CLI Python + MySql + Docker program as a sample..............................36
- Installing the MySql driver.......................................................37
- Dockerfile....................................................................38
- build_docker.sh................................................................39
- docker_run.sh.................................................................39
- docker_run_mysql.sh...........................................................40
- start.sql......................................................................41
- select_values_example.py.......................................................42
- Executing the Container.........................................................42
- Entering the Container and running the code.........................................44
- Tying together MySQL and a Python Menu with Object Oriented Programming.............44
- MySQL Library...............................................................45
- A Data Object: CarDO..........................................................46
- Queue Manager................................................................48
- Bonus.......................................................................54
- A Dockerfile with PHP, Apache and Catalonia Frameworks...............................55
- End of life of images............................................................56
- Create the Dockerfile...........................................................56
- The www.cataloniaframework.com.conf file.........................................59
- Stopping, starting the docker Service and creating the Catalonia image....................60
- Building with --no-cache option...................................................60
- Trying the Container working.....................................................61
- A base Dockerfile for your Jenkins deployments........................................63
- The EXPOSE instruction........................................................66
- Build the Container.............................................................66
- Run the Container displaying the password..........................................66
- Mapping the ports with -p........................................................67
- Configure Jenkins with Projects and Pipelines........................................70
- Install jenkins on Docker with Blue Ocean and persisten Voluemes in Ubuntu 20.04 LTS........71
- Usage of USER Command.......................................................72
- Why I propose you to use Python 3.8, at least, for your Internal Automation Tools in Docker
- Containers and Ubuntu LTS........................................................76
- Reliability and Maturity.........................................................76
- A sample Star Wars Python 3 Flask Applications........................................78
- MT Notation..................................................................82
- The Dockerfile for flask.........................................................82
- Installing PIP3 Requirements with pip3 install -r requirements.txt........................83
- Defining Environment Variables in the Container with ENV............................83
- File requirements.txt............................................................84
- build_docker.sh................................................................84
- Refreshing settings in a Docker immutable image with Python and Flask.....................85
- Smaller Images................................................................88
- Using Docker for Unit Testing......................................................89
- Using Docker for running a demo....................................................89
- Making a Container start automatically...............................................91
- Docker Volumes.................................................................92
- Launch a Container using a specific Volume.........................................93
- Launching a Container with a bind mount (local folder)..................................94
- Docker compose.................................................................98
- Docker-compose with LAMP and PHPMyAdmin......................................104
- Volumes....................................................................107
- Port collision.................................................................107
- Exporting and Importing Docker Images.............................................108
- Docker logs..................................................................109
- Docker container ps -a............................................................110
- Cleaning what you don’t use: docker system prune.....................................110
- DockerHub.....................................................................111
- Docker information..............................................................116
- Limit containers resources.........................................................117
- Limit the Memory of the Containers.................................................117
- Limit the CPU for the Containers...................................................117
- Adding an additional user, so you don’t have to run as root...............................118
- Using a different user in the Containers.................................................119
- Launching a jenkins Docker Container...............................................120
- Checking the logs from a Container....................................................124
- Communicating with Docker Containers via Linux Signals and Python – docker kill..........124
- The Dockerfile...............................................................125
- The dockersignal.py file........................................................125
- build_and_run_docker.sh.......................................................126
- Tools and Tricks...................................................................128
- Reverse Engineering a Docker image to get the founding Dockerfile (dfimage)...............128
- Lazy Docker...................................................................132
- ctop..........................................................................134
- CTOP.py......................................................................135
- Using Docker in Windows 10 without Windows Desktop with Docker Engine and without WSL. 136
- Installing Docker Command line binaries..........................................137
- Turn Windows features on or off.................................................138
- Enable Experimental Mode.....................................................139
- Switch Daemon...............................................................140
- Troubleshooting...................................................................142
- Troubleshooting a failing Docker Container...........................................142
- Solving the problem when running an Alpine Docker Container: standard_init_linux.go:190: exec
- user process caused “no such file or directory”........................................142
- A typical copy and paste error......................................................144
- If a Container does not start.......................................................145
- Running out of space.............................................................146
- Space taken from Images.......................................................146
- Space taken from logs..........................................................146
- Using the Docker SDK.............................................................150
- MT Notation...................................................................150
- Installing the requirements........................................................150
- The most basic examples..........................................................151
- Run a Container..............................................................151
- Run a Container in Background..................................................151
- Pull an Image................................................................151
- List the Containers............................................................152
- Videos........................................................................154
- Docker SDK from Python demo (7m 55secs).......................................154
- Docker-compose up demo (4m 10secs)............................................154
- Docker SDK Demo Python 3 program.................................................155
- Running the program.............................................................155
- Setting PyCharm................................................................156
- To Run the demo from command line.............................................159
- First look at the code...........................................................162
- List Containers (first version)......................................................164
- Run the Container ubuntu:latest with echo hello world (bonus)............................166
- Running a Container.............................................................167
- Reverse Engineering to get what I need..............................................169
- List of all Containers (pretty version)................................................172
- Stop a Container................................................................174
- Deleting all the stopped Containers..................................................177
- Finding the prune equivalent.......................................................178
- Writing a Dockerfile and running the Container........................................180
- The docker-compose project.......................................................185
- Recommended bibliography.........................................................189
- Official Docker Documentation....................................................189
- Python Docker SDK.............................................................189
- Books.........................................................................189
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
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,046,757writing, publishing and selling on Leanpub.
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) and EPUB (for phones, tablets and 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
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.
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.
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.
Talking with Tech Leads
Patrick KuaA book for Tech Leads, from Tech Leads. Discover how more than 35 Tech Leads find the delicate balance between the technical and non-technical worlds. Discover the challenges a Tech Lead faces and how to overcome them. You may be surprised by the lessons they have to share.Functional Event-Driven Architecture
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
Take your functional programming skills to the next level by joining me in developing a distributed system powered by Apache Pulsar and Fs2 streams, all in Scala 3!
Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
The Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
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.
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... - #3
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #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... - #5
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #6
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #8
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for...