Cover ImageBeginning DevOps with Docker
Joseph Muli

27 notes/highlights

Created by Ahmed Mansour Ouda   – Last synced January 22, 2022


You need to have a basic knowledge about UNIX concepts such as ssh, ports, and logs as we dive into Docker.
January 17, 202214

In virtual machines, the physical hardware is abstracted, therefore we have many servers running on one server. A hypervisor helps do this. Virtual machines do sometimes take time to start up and are expensive in capacity (they can be GBs in size), although the greatest advantage they have over containers is the ability to run
January 18, 202224

In containerization, it is only the app layer (where code and dependencies are packaged) that is abstracted, making it possible for many containers to run on the same OS kernel but on separate user space. Containers use less space and boot fast. This makes development easier, since you can delete and start up containers on the fly without considering how much server or developer working space you have.
January 18, 202225

The Dockerfile takes the place of the provisioning script. The two combined (project code and Dockerfile) make a Docker image. A Docker image can be run as an application. This running application sourced from a Docker image is called a Docker container.
January 20, 202227

The repository is simply the image name unless it is sourced from a different registry. In this case, you’ll have a URL without the http:// and the top level domain (TLD) such as >registry.heroku.com/ from the Heroku registry.
January 20, 202232

Separation of concern : Ensure each Dockerfile is, as much as possible, focused on one goal. This will make it so much easier to reuse in multiple applications. Avoid unnecessary installations : This will reduce complexity and make the image and container compact enough. Reuse already built images : There are several built and versioned images on Docker Hub; thus, instead of implementing an already existing image, it’s highly advisable to reuse by importing. Have a limited number of layers : A minimal number of layers will allow one to have a compact or smaller build. Memory is a key factor to consider when building images and containers, because this also affects the consumers of the image, or the clients.
January 20, 202234

To delete the images that are non-tagged (assumed not to be relevant), knowledge of bash scripting comes in handy. Use the following command: docker rmi $(docker images | grep “^” | awk “{print $3}”)
January 21, 202238

Remember when we mentioned containers are built from images? The command docker run creates a container based on that image. One can say that a container is a running instance of an image. Another reminder is that this image could either be local or in the registry.
January 21, 202240

We get into an interactive bash shell in the container. -it instructs the Docker container to create this shell.
January 21, 202241

This versioning system is called semver: semantic versioning. This version number has the format MAJOR, MINOR, PATCH in an incremental manner: MAJOR : For a change that is backward-incompatible MINOR : For when you have a backward-compatible change PATCH : For when you make bug fixes that are backward-compatible
January 21, 202243

In summary, docker-compose is the tool used for defining and running multi-container Docker applications.
January 21, 202247

You can run docker run with ( -d ) as detached to prevent us from running the three commands in separate sessions, for example: docker run -d That said, it even becomes particularly tasking linking different containers (networking). docker-compose comes in to save the day. We can define and run multi-containers from one file – docker-compose.yml . In the following topics, we’ll discuss this further. First, let’s install it.
January 21, 202248

In a Dockerfile, every line describes a layer. The union filesystem used in Docker allows different directories to transparently overlay, forming a single, coherent filesystem. The foundational layer is always an image which you build upon. Each additional line with a command, say, RUN, CMD, and so on, adds a layer to it.
January 21, 202250

The Frontend When you open a web application, the page that you see is part of the frontend. Sometimes, the frontend has the controller (the logical end) and the view layer (the dumb end). The styling of the layout and content (Read, HTML, and CSS) is the view layer. The content here is managed by the controller.
January 21, 202250

The Database The database contains organized data (information) that is easily accessible, managed, and updated. We have file-based databases and server-based databases. Server-based databases involve a server process running, accepting requests and reading and writing the database files themselves. The databases could be in the cloud, for example.
January 21, 202251

PREN – PostgresDB, React, Express, Node.js MEAN – MongoDB, Express, Angular, Node.js VPEN – VueJS, PostgresDB, Express, Node.js LAMP – Linux, Apache, MySQL, PHP
January 21, 202252

docker-compose.yml is a YAML file. It defines services, networks , and volumes .
January 21, 202254

Services are application container definitions that include all components that relate to an application, for example, DB, frontend , or backend . What really weighs in when defining services is the components, which are networks, volumes, and environment variables.
January 21, 202254

Running docker-compose up -d is running docker-compose up in detached mode. That is, the command will be running in the background.
January 22, 202256

The number 0.0.0.0 defines the host address running the container. Note The address tells docker-compose to run the container on our machine or, in short, localhost. If we were to skip the address and just expose the port, our set up would have unexpected results like a blank page.
January 22, 202260

you’ll notice that port 3306 is exposed. This is the standard port for MySQL. You can obtain more information on MySQL from: https://hub.docker.com/r/library/mysql. Note We don’t have port mapping for DB because we don’t necessarily need the port mapped to our computer; instead, we want the WordPress app mapped to the DB for communication.
January 22, 202263

First, let’s get familiarized with some of the terms used when it comes to orchestration: docker-engine : This refers to the Docker bundle or installation we currently have on our computers docker-machine : A tool that helps us install Docker on virtual hosts Virtual hosts : These are virtual servers that run under physical
January 22, 202268

hosts docker-swarm : A clustering tool for Docker docker host : A host or server that has Docker set up or installed Node : A Docker host that is connected to a swarm cluster Cluster : A group of Docker hosts or nodes Replica : A duplicate or number of duplicates of an instance Task : A defined operation to be run on nodes Service : A group of tasks
January 22, 202268

Docker Swarm is a clustering tool for Docker containers. It allows you to establish and manage a cluster of Docker nodes as a single virtual system . This means we get to run Docker on multiple hosts on our computers.
January 22, 202269

Clustering is important because it creates a group of cooperating systems that provide redundancy, creating a fault-tolerant environment. For example, if one or more of the nodes goes down, Docker Swarm will fail over to another working node.
January 22, 202269

Remember, a node is a host running Docker , not a container.
January 22, 202269

Write A Comment