Skip to content

Instantly share code, notes, and snippets.

@mkfares
mkfares / zsh-keyboard-shortucts.md
Last active May 13, 2024 19:25
Common zsh Keyboard Shortcuts on macOS Catalina

Common zsh Keyboard Shortcuts on macOS

Navigation

CTRL + A : Move the cursor to the beginning of the line
CTRL + E : Move the cursor to the end of the line
OPTION + Left Arrow : Move the cursor one word backward
OPTION + Right arrow : Move the cursor one word forward
Left Arrow : Move the cursor one character backward
Right Arrow : Move the cursor one character forward

@mkfares
mkfares / docker-managing-images.md
Last active July 29, 2020 10:11
Docker Managing Images

Managing Docker Images

Image names

The image name is composed of two parts that are separated by a colon (:) repository:tag. For instance, in the image name alpine:3.12, the repository is alpine and the tag is 3.12. The default tag is latest if it is omitted from the image name. For example, alpine is equivalent to alpine:latest.

Pull images from Docker Hub Registry

$ docker image pull alpine
$ docker image pull alpine:3.12
@mkfares
mkfares / docker-managing-containers.md
Last active July 29, 2020 10:10
Docker Managing Containers

Managing Docker Containers

Most of tasks that are related to the management of containers are performed using the command: docker container. However, some commands process a short notation.

A container or an image can be mentioned by its name (see option --name) or by its id. The container id can be shortened to the few first unique characters.

Create new containers

The container is created but not started. This helps speedup the starting and running of containers.

@mkfares
mkfares / docker-creating-images.md
Created July 29, 2020 10:09
Create Docker Images

Creating Docker Images

Create images interactively

The creation of images interactively is done in multiple steps.

Create and run containers from images

$ docker run -it --name calpine alpine  
@mkfares
mkfares / docker-working-with-registries.md
Created July 29, 2020 12:58
Working with Docker Registries

Working with Registries

Registry: It is server where container images are stored and shared with other users. Registries may be private or public. The default registry is Docker Hub (docker.io).

Repository: It is a grouping of related container images. Usually, it contains an image with multiple versions. A registry may contain multiple repositories.

Tag: It is a version number or a name given to an image. An image name is composed of the name itself and a tag. The name follow the form image_name:tag ( alpine:3.1, alpine:latest). If the tag is not provided, the latest is assumed.

Image namespace: It is the fully qualified name of an image. It include the registry, username / organization, repository, image name, and image tag (myregistry.com/username/linux/fedora:32.0)

@mkfares
mkfares / docker-working-with-docker-storage-and-volumes.md
Last active February 9, 2024 19:53
Working with Docker Storage and Volume

Working with Storage and Volumes

Containers do not persist the generated data when they are removed; hence, the data will be lost. The storage of data permanently is achieved in three different ways:

  • Volumes
  • Bind mounts
  • In-memory storage

Volume: It is a directory created by the docker engine on the host. It is isolated from the host filesystem. It is fully managed by docker engine.

@mkfares
mkfares / docker-managing-networks.md
Created August 1, 2020 12:41
Managing Docker Networks

Managing Docker Networks

Default networks

The docker engine creates three types of networks (drivers) when installed. These types of network are ready to be used by containers.

Bridge network: This network uses a software bridge (layer 2 switch) to connect containers that are running on the same host. These containers communicate with each other and are isolated from containers that are not connected to the same bridge. A newly created container joins the default bridge unless a user-defined bridge is specified.

Host network: This is the network to which the docker host is connected. Containers connected to this network can communicate with the host without port mappings. This network works only on linux systems.

@mkfares
mkfares / docker-publishing-ports.md
Created August 2, 2020 03:05
Publishing Docker Ports

Publishing Docker Ports

Containers expose its services through ports. These ports are numbers that represent a running applications inside the containers. For instance, a web server container exposes the ports 80 and/or 443 to allow other containers and the docker host to connect to this web server. Exposing a port to the outside is also known as port publishing.

Without port publishing, services running inside containers are not accessible to other containers or to the host. They are only accessible from inside the container.

Publish all container ports to random host ports

The -P option (i.e., capital p or --publish-all) allows you to expose all container ports to a randomly selected ports on the docker host. The -P option is set during the creation of the container or when starting a container.

Introducing YAML

YAML (YAML Ain’t Markup Language) is a data serialization language. It was designed to be human-friendly. It organizes data into a readable structure with a simple notation. YAML is based on key-value pairs, indentation, and few punctuations such as colon (:) and hyphens (-).

YAML includes three representations: scalars, sequences and mappings. Among scalars are strings, numbers, and boolean data types. The sequences are similar to lists and arrays in programming languages. The mappings are hashes and dictionaries.

YAML resembles JSON notation. The YAML specification 1.2 states that YAML is a superset of JSON, which means, a JSON file is a valid YAML file.

YAML has many applications. It is mainly used in configuration files, log files, and data sharing between applications.

YAML uses key-value format. The key-value pair specified as: key: value. Here, the colon should be followed by a space.

@mkfares
mkfares / docker-compose-file.md
Last active August 5, 2020 05:46
Docker Compose File

Docker Compose File

Modern applications rely on multiple components, or services, such as database, back-end, front-end, web API, and file sharing. Managing these components can be a difficult task because of the update and security tasks.

Docker compose allows the coordination of multiple containers on a single host. It includes two components : the docker-compose command which helps managing the containers and the docker compose file which defines the services and resources.

Docker compose is included as part of the docker desktop. On Linux, you need to install it after installing the docker engine.

When working with docker compose, we talk about services instead of containers. Services are similar to containers, but they are scaled up and down, restarted if stopped, and can run on multiple nodes.