Skip to content

Commit

Permalink
show line numbers in conde snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lamonaca committed Oct 24, 2023
1 parent 09b46d5 commit b308443
Show file tree
Hide file tree
Showing 82 changed files with 1,249 additions and 1,251 deletions.
28 changes: 14 additions & 14 deletions docs/containers/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ VMs incur a lot of overhead beyond what is being consumed by your application lo

### [`docker run`](https://docs.docker.com/engine/reference/commandline/run/)

```sh
```sh linenums="1"
docker run <image> # run selected app inside a container (downloaded from Docker Hub if missing from image)
docker run -d|--detach <image> # run docker container in the background (does not occupy stdout & stderr)
docker run -i|--interactive <image> # run docker container in interactive mode (read stdin)
Expand All @@ -80,7 +80,7 @@ docker run --name=<container_name> <image> # set container name
### [`docker container`](https://docs.docker.com/engine/reference/commandline/container/)

```sh
```sh linenums="1"
docker container ls # list of currently running containers
docker container ls -a|--all # list of all containers, running and exited
docker container rm <container> # remove one or more containers
Expand All @@ -97,7 +97,7 @@ docker container exec <container> <command> # exec a command inside a container

### [`docker image`](https://docs.docker.com/engine/reference/commandline/image/)

```sh
```sh linenums="1"
docker image ls # list of existing images
docker image rm <image> # remove one or more images
docker image prune <image> # remove unused images
Expand All @@ -106,20 +106,20 @@ docker image pull <image> # download an image w/o starting the container

### [`docker build`](https://docs.docker.com/engine/reference/commandline/build/)

```sh
```sh linenums="1"
docker build -t <tag> -f <dockerfile> <context> # build image with specific tag (usually user/app:version)
docker build -t <tag> -f <dockerfile> --build-arg ARG=value <context> # pass args to ARG steps
```

### [`docker push`](https://docs.docker.com/engine/reference/commandline/push/)

```sh
```sh linenums="1"
docker push <image> # publish image to registry (defaults to Docker Hub)
```

## [Dockerfile](https://docs.docker.com/engine/reference/builder/)

```docker
```docker linenums="1"
# starting image or scratch
FROM <base_image>:<tag>
Expand Down Expand Up @@ -149,7 +149,7 @@ ENTRYPOINT <executable> <arg1> <arg2>

### `CMD` vs `ENTRYPOINT`

`CMD` is used to provide all the default scenarios which can be overridden. _Anything_ defined in CMD can be overridden by passing arguments in `docker run` command.
`CMD` is used to provide all the default scenarios which can be overridden. *Anything* defined in CMD can be overridden by passing arguments in `docker run` command.

`ENTRYPOINT` is used to define a specific executable (and it's arguments) to be executed during container invocation which cannot be overridden.
The user can however define arguments to be passed in the executable by adding them in the `docker run` command.
Expand All @@ -160,7 +160,7 @@ With multi-stage builds, it's possible to use multiple `FROM` statements in the

It's possible to selectively copy artifacts from one stage to another, leaving behind everything not wanted in the final image.

```docker
```docker linenums="1"
FROM <base_image>:<tag> AS <runtime_alias>
RUN <command> # install external dependencies (apt get ...)
Expand All @@ -186,7 +186,7 @@ COPY --from=<build_alias|stage_number> <src> <dir_in_container>
CMD ["executable"] # run app
```

```docker
```docker linenums="1"
FROM mcr.microsoft.com/dotnet/<runtime|aspnet>:<alpine_tag> AS runtime
RUN <command> # install external dependencies (apt get ...)
Expand Down Expand Up @@ -219,7 +219,7 @@ ENTRYPOINT ["dotnet", "<project>.dll"]

Starting container networks: `bridge` (default), `none`, `host`.

```sh
```sh linenums="1"
docker run <image> --network=none/host # specify a non-default network to be used
docker network ls # list all available networks
```
Expand All @@ -233,7 +233,7 @@ None: Containers are not attached to a network and cannot access other container

## User-defined Networks

```sh
```sh linenums="1"
docker network create \
--driver NETWORK_TYPE \
--subnet GATEWAY_TP/SUBNET_MASK_SIZE
Expand All @@ -250,7 +250,7 @@ Docker has an internal DNS that allows finding other container by their name ins

## File System

```sh
```sh linenums="1"
/var/lib/docker
|_<storage_driver>
|_containers
Expand All @@ -270,7 +270,7 @@ To modify a file during while the container runs docker creates a local copy in
**volume mounting**: create a volume under the docker installation folder (`/var/lib/docker/volumes/`).
**bind mounting**: link docker to an exiting folder to be used as a volume.

```sh
```sh linenums="1"
docker run -v <existing_dir>:<container_dir> <image>:<tag> # older command for bind mounting
docker run --mount type=bind, source=:<existing_dir>, target=<container_dir> <image>:<tag> # modern command for bind mounting
```
Expand All @@ -287,7 +287,7 @@ Using Compose is basically a three-step process:
2. Define the services that make up your app in `docker-compose.yml` so they can be run together in an isolated environment.
3. Run `docker-compose up` and Compose starts and runs the entire app.

```yaml
```yaml linenums="1"
version: 3.x
services:
<service_name>:
Expand Down
11 changes: 6 additions & 5 deletions docs/containers/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ As pods successfully complete, the Job tracks the successful completions. When a

## Kubernetes Configuration

Each kubernetes configuration file is composed by 3 parts:
Each kubernetes configuration file is composed by 3 parts:

- metadata
- specification
Expand All @@ -110,7 +110,7 @@ Each kubernetes configuration file is composed by 3 parts:

### `kubectl get`

```sh
```sh linenums="1"
kubectl config get-contexts # list available contexts

kubectl get namespaces # list namespaces inside current context
Expand All @@ -121,11 +121,12 @@ kubectl get pod [-n|--namespace <namespace>] <pod> -o|--output jsonpath='{.spec.

### `kubectl exec`

```sh
```sh linenums="1"
kubectl exec [-i|--stdin] [-t|--tty] [-n|--namespace <namespace>] <pod> [-c|--container <container>] -- <command> # execute a command inside a container
```

### `kubectl logs`

```sh
```sh linenums="1"
kubectl logs [-f|--follow] [-n|--namespace <namespace>] <pod> [-c|--container] # get pod/container logs
```
```
Loading

0 comments on commit b308443

Please sign in to comment.