Docker

How to use docker

Best-practices

Aka optimizations

Perform your add & remove operations in the same RUN command. Doing them separately creates two separate layers which inflates the image size.

This creates two image layers - the first layer has all the added foo, including any intermediate artifacts. Then the second layer removes the intermediate artifacts, but that's saved as a diff against the previous layer:

RUN ./install-foo RUN ./cleanup-foo

>
> Instead, you need to do them in the same RUN command:
>
> ```docker
RUN ./insall-foo && ./cleanup-foo

This creates a single layer which has only the foo artifacts you need.

This why the official Dockerfile best practices show the apt cache being cleaned up in the same RUN command:

RUN apt-get update && apt-get install -y package-bar package-baz package-foo && rm -rf /var/lib/apt/lists/*

>
> — [A common mistake that's not covered in this article is the need to perform your ... | Hacker News](https://news.ycombinator.com/item?id=29830364)

```docker
RUN <<EOF
	apt-get update
	apt-get install -y foo bar baz
	etc...
EOF

Lint and security:

Docker compose

Aka compose.yaml (or docker-compose.yml or compose.yml)

Alpine

FROM alpine:3.11

RUN set -x \
    && apk add --no-cache bash
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main package

http://nl.alpinelinux.org/alpine/v3.11/main/ http://dl-cdn.alpinelinux.org/alpine/edge/community

How docker works

AMP

Aka LAMP, Linux Apache MySQL PHP

Virtual Machine

If the host is not Linux or the image use on other OS use a virtual machine container

macOS

Volumes

WebAssembly

Aka wasm

Last updated