manuais-e-documentacao-itguys/documentacao conteineres/Instalacao_Docker_Compose_L...

123 lines
4.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

# MANUAL TÉCNICO - INSTALAÇÃO E CONFIGURAÇÃO DO DOCKER E COMPOSE (LINUX)
**Código:** ITGSUP 0007/26 | **Classificação:** RESTRITO
**Responsável:** João Pedro Toledo Gonçalves | **Data:** {{DATA_ATUAL}}
## 1. HISTÓRICO DE REVISÃO
> ⚠️ **REGRA DE OURO:**
> 1. **Autor:** João Pedro Toledo Gonçalves.
> 2. **Descrição:** Criação do documento.
| Data | Versão | Descrição | Autor |
| :--- | :--- | :--- | :--- |
| {{DATA_ATUAL}} | 1.0 | Criação Inicial | João Pedro Toledo Gonçalves |
## 2. OBJETIVO
Padronizar a instalação do Docker Engine e Docker Compose em servidores Linux (Ubuntu/Debian), garantindo suporte oficial e atualizações seguras.
## 3. PRÉ-REQUISITOS
> Liste o que é necessário ANTES de começar.
* [ ] Acesso ao servidor via SSH.
* [ ] Usuário com privilégios de `sudo` ou `root`.
* [ ] Conexão com a internet liberada (Portas 80/443).
* [ ] Sistema Operacional compatível (Ubuntu 20.04+, Debian 11+).
## 4. PASSO A PASSO (EXECUÇÃO)
**Etapa 1: Preparação do Ambiente e Repositórios**
1. Atualize o índice de pacotes e instale as dependências essenciais para HTTPS.
```bash
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
```
2. Adicione a chave GPG oficial do Docker para garantir a autenticidade dos pacotes.
```bash
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
```
3. Configure o repositório estável.
> **NOTA:** O comando abaixo detecta automaticamente a versão do OS (`lsb_release`).
```bash
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
**Etapa 2: Instalação dos Pacotes**
1. Atualize novamente o índice (agora com o repo do Docker) e instale o Engine, CLI e plugins.
```bash
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
**Etapa 3: Pós-Instalação (Permissões)**
> ⚠️ **IMPORTANTE:** Execute isso para **não** precisar usar `sudo` em todo comando docker.
1. Adicione seu usuário atual ao grupo `docker`.
2. Aplique a mudança de grupo na sessão atual.
```bash
sudo usermod -aG docker $USER
newgrp docker
```
**Etapa 4: Validação (Hello World)**
1. Execute o container de teste para validar a instalação completa.
```bash
docker run hello-world
```
2. O resultado esperado deve ser idêntico ao bloco abaixo:
> [!NOTE]
> Sucesso na execução do Docker.
```text
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
```
## 5. SOLUÇÃO DE PROBLEMAS (TROUBLESHOOTING)
**Problema 1: "permission denied while trying to connect to the Docker daemon socket"**
* **Causa:** O usuário não está no grupo `docker` ou a sessão não foi atualizada.
* **Solução:**
1. Execute `sudo usermod -aG docker $USER`.
2. Faça **logoff** e login novamente ou use `newgrp docker`.
**Problema 2: Erro de GPG ou Repositório não encontrado**
* **Causa:** Chave expirada ou OS não suportado.
* **Solução:**
1. Verifique se o codename do OS em `/etc/os-release` é compatível (focal, jammy, bullseye, bookworm).
2. Remova o arquivo `/etc/apt/sources.list.d/docker.list` e refaça a **Etapa 1**.
## 6. DADOS TÉCNICOS
| Campo | Valor | Descrição |
| :--- | :--- | :--- |
| **Serviço** | `docker.service` | Nome do serviço no Systemd |
| **Config** | `/etc/docker/daemon.json` | Arquivo principal de configuração |
| **Dados** | `/var/lib/docker` | Local padrão de imagens e volumes |
| **Socket** | `/var/run/docker.sock` | Socket de comunicação da API |
## 7. VALIDAÇÃO FINAL (Definição de Pronto)
- [ ] O comando `docker run hello-world` funciona sem sudo?
- [ ] O comando `docker compose version` retorna a versão (ex: v2.x.x)?
- [ ] O serviço está ativo? (`sudo systemctl status docker` mostra **active (running)**)