til/Development/Docker.md

71 lines
1.7 KiB
Markdown
Raw Normal View History

2020-03-21 09:24:35 +00:00
# Docker
2020-05-09 18:30:08 +00:00
| Distribution | Package |
| ------------ | ----------------------------------------------------- |
2020-05-24 10:44:40 +00:00
| Arch Linux | `docker` |
2020-05-09 18:30:08 +00:00
| Ubuntu | [See](https://docs.docker.com/engine/install/ubuntu/) |
2020-03-21 09:24:35 +00:00
2020-05-25 10:14:17 +00:00
Enable and start service:
2020-03-31 07:46:58 +00:00
```sh
2020-05-09 16:16:00 +00:00
systemctl enable --now docker.service
2020-03-31 07:46:58 +00:00
```
Add your user to `docker` group:
```sh
sudo usermod -aG docker $USER
```
2020-03-21 09:24:35 +00:00
2020-07-23 08:14:13 +00:00
## Commands
2020-06-12 10:08:46 +00:00
Remove unused data:
2020-03-21 09:24:35 +00:00
```sh
2020-07-20 08:45:32 +00:00
docker system prune --volumes
2020-03-31 09:26:22 +00:00
2020-07-20 08:45:32 +00:00
docker system prune --volumes -a
2020-03-31 09:26:22 +00:00
```
2020-06-12 10:08:46 +00:00
2020-07-23 08:14:13 +00:00
Inside container:
```sh
docker exec -it container_name /bin/bash
```
2020-06-12 10:08:46 +00:00
Docker run options:
| option | example | explain |
| --------------------- | ------------------------ | --------------------------------------- |
| `--detach`, `-d` | | Run container in background |
| `--env`, `-e` | `-e PLATFORM=linux` | Set environment variables |
| `--interactive`, `-i` | | Keep STDIN open |
| `--name` | | |
| `--publish`, `-p` | `-p 8080:80` | Publish container port:host port |
| `--rm` | | Remove container when exit |
| `--tty`, `-t` | | Allocate a pseudo-TTY |
| `--volume`, `-v` | `-v "$(pwd)"/data:/data` | Bind host directory:container directory |
2020-07-13 07:27:08 +00:00
## Docker Compose
Update images:
```sh
docker-compose pull
```
Start:
```sh
docker-compose up
# Detach
docker-compose up -d
```
Stops:
```sh
docker-compose down
```