Para considerar o arquivo host-compose.yaml deve ser acrescentada a opção "-f host-compose.yaml":
~/compose$ docker compose -f host-compose.yaml up -d
[+] Running 0/0
⠋ Network compose_default Creating 0.1s
WARN[0000] Found orphan containers ([compose-postgre-1 compose-kubenews-1]) for this [+] Running 2/2 removed or renamed this service in your compose file, you can run thi
✔ Network compose_default Created 0.1s
✔ Container compose-nginx-1 Started 0.4s
Container em execução
~/compose$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fae888555c1 nginx "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp compose-nginx-1
Inspeção do container onde é possível verificar a utilização da rede bridge:
Subir novamente o Docker Compose e inspecionar o container:
~/compose$ docker compose -f host-compose.yaml up -d
[+] Running 1/1
✔ Container compose-nginx-1 Started 0.7s
~/compose$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f8b3a9e406bd nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds compose-nginx-1
~/compose$ docker compose -f host-compose.yaml up -d
[+] Running 2/2
✔ Container compose-nginx-1 Running 0.0s
✔ Container compose-curl-1 Started 0.3s
O container foi criado:
~/compose$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65d5d33114aa nginx "/docker-entrypoint.…" 31 seconds ago Up 31 seconds 80/tcp compose-curl-1
f8b3a9e406bd nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes compose-nginx-1
Entrando nos containers em modo interativo é possível verificar a linha de entrada do host na bridge:
Ainda no modo interativo do container compose-curl-1 é possível acessar o container compose-nginx-1:
root@65d5d33114aa:/# curl http://192.168.43.217
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Domínios
Edição do arquivo host-compose.yaml para adicionar "extra_hosts" sem a necessidade de editar o arquivo "/etc/hosts":
~/compose$ docker compose -f host-compose.yaml up -d
[+] Running 2/2
✔ Container compose-curl-1 Started 0.8s
✔ Container compose-nginx-1 Running 0.0s
Lista os containers:
~/compose$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d46d7fd09b26 nginx "/docker-entrypoint.…" 29 seconds ago Up 27 seconds 80/tcp compose-curl-1
f8b3a9e406bd nginx "/docker-entrypoint.…" 19 minutes ago Up 19 minutes compose-nginx-1
Entrar no modo interativo novamente e o acesso ao domínio:
~/compose$ docker container exec -it compose-curl-1 /bin/bash
root@d46d7fd09b26:/# curl http://docker.barbieri.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>