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.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $13 millionwriting, 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