tech-tips/Программное обеспечение/Docker/Быстрый старт. Частые команды.md

51 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
tags: [docker, docker-compose]
---
```shell
docker create -it ubuntu:18.04 bash
docker start <id>
docker attach <id>
docker exec <id> <cmd>
docker ps -a
```
Подключиться к консоли контейнера:
```shell
docker exec -ti <id> /bin/bash
docker attach <id>
```
Построить контейнеры в директории с файлом `docker-compose.yaml`
```shell
docker-compose up --build -d
```
Узнать IP конкретного контейнера
```shell
docker exec <id> cat /etc/hosts
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <id>
```
Узнать IP всех запущенных контейнеров:
```shell
docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##';
docker-compose ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##';
```
Docker-compose: подключить контейнеры к bridge хоста:
> Adding network_mode: bridge to each service in your docker-compose.yml will stop compose from creating a network. If any service is not configured with this bridge (or host), a network will be created. Tested and confirmed with:
```yaml
version: "3.1"
services:
app:
image: ubuntu:latest
network_mode: bridge
```