Criação básica de um Docker Compose

$ cd ~
$ mkdir compose
$ cd compose
/compose$
$ touch compose.yaml
$ vim compose.yaml

Ao invés de executar o container com o comando abaixo, será criagado com o compose:

$ docker container run -d -p 8080:8080 nginx:latest

compose.yaml:

version: "3.8"

services:
  nginx:
    image: nginx:latest
    ports:
      - "8080:80"

Subida do docker compose. O terminal ficou travado:

$ docker compose -f compose.yaml up
WARN[0000] /home/marcelo/compose/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 1/0
  Container compose-nginx-1  Created                                                        0.0s
Attaching to nginx-1
nginx-1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx-1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx-1  | 10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
nginx-1  | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx-1  | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: using the "epoll" event method
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: nginx/1.27.1
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: OS: Linux 5.15.146.1-microsoft-standard-WSL2
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker processes
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker process 22
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker process 23
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker process 24
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker process 25
nginx-1  | 2024/09/03 10:51:31 [notice] 1#1: start worker process 26

Subida do compose em mode dettached:

O container está sendo executado e pode ser acessado:

Se o arquivo compose.yaml for alterado ele automaticamente recria o container. Por exemplo, alterar a porta para 8081:

O nome do container pode ser especificado ao invés de utilizar o nome padrão:

Pode-se reescrever o comando com o Docker Compose ao invés de utilizar o comando abaixo:

Baixar o Docker Compose:

Parar o Docker Compose:

Iniciar o Docker Compose:

Pode ser especificado muliplos containers:

Last updated