Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
777b80d
commit 9a10859
Showing
2 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |