Skip to content

Commit

Permalink
Migrate docker articles
Browse files Browse the repository at this point in the history
  • Loading branch information
skrysmanski committed Feb 4, 2024
1 parent 777b80d commit 9a10859
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
115 changes: 115 additions & 0 deletions content/articles/docker/cheat-sheet.md
@@ -0,0 +1,115 @@
---
title: Docker Cheat Sheet
date: 2018-12-29
topics:
- docker
- cheat-sheet
---

## Installing Docker

### Windows

<https://hub.docker.com/editions/community/docker-ce-desktop-windows>

### MacOS

<https://hub.docker.com/editions/community/docker-ce-desktop-mac>

### Linux

```shell
CHANNEL=stable sh -c "$(curl -fsSL https://get.docker.com)"
```

### Test Docker

```shell
docker run --rm hello-world
```

## Running Containers

Run container in *foreground*:

```shell
docker run --rm -ti <imagename>
```

Run container in *background*:

```shell
docker run --rm -d <imagename>
```

Port mapping:

```shell
docker run -p <host_port>:<container_port> ...
```

Container name:

```shell
docker run --name <containername> ...
```

Mount host volume:

```shell
docker run -v <abs_dir_host>:<abs_dir_container>
docker run -v $(pwd)/<rel_dir_host>:<abs_dir_container> ...
```

## Building Images

Build container:

```shell
docker build --tag <imagename> .
```

## Debugging and Analysis

Get into a container

```shell
docker exec -ti <container> bash
```

## Listing Things

All images:

```shell
docker images
```

All running containers:

```shell
docker ps
```

All containers (including stopped):

```shell
docker ps -a
```

Volumes/Mounts of a container:

```shell
docker container inspect -f '{{ range .Mounts }}{{ .Name }}:{{ .Destination }} {{ end }}' <container>
```

## Cleanup

See: <https://docs.docker.com/config/pruning/>

```shell
docker system prune
docker image prune
docker container prune
docker volume prune
```
57 changes: 57 additions & 0 deletions content/articles/docker/docker-compose.md
@@ -0,0 +1,57 @@
---
title: docker-compose
date: 2020-02-01
topics:
- docker
---

## Basics

Start:

```shell
docker-compose up
docker-compose up -d
```

Shutdown:

```shell
docker-compose down
```

## docker-compose.yml

The default name for the **compose file** is:

docker-compose.yml

Reference: <https://docs.docker.com/compose/compose-file/>

Version Changelog: <https://docs.docker.com/compose/compose-file/compose-versioning/#version-3>

### Example

**Important:** This example file is not supposed to be working. It's just a "random" collection of useful compose directives.

```yml
version: '3.1'

services:
wordpress:
image: wordpress
ports:
# Exposes port 80 from container on 8080 on host
# NOTE: Always use strings or the numbers will be interpreted as base 60.
- "8080:80"
volumes:
# Host mounted volume
- ./html:/var/www/html:ro
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser

db:
image: mysql:5.7
restart: always
```

0 comments on commit 9a10859

Please sign in to comment.