51 lines
1.4 KiB
Markdown
51 lines
1.4 KiB
Markdown
|
---
|
|||
|
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
|
|||
|
```
|