Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
# List Docker networks docker network ls # Create a user-defined bridge network docker network create --driver bridge app-network # Run containers on the same network (DNS by container name) docker run -d \ --name db \ --network app-network \ -e POSTGRES_PASSWORD=secret \ postgres:16-alpine docker run -d \ --name api \ --network app-network \ -e DATABASE_URL=postgres://postgres:secret@db:5432/postgres \ -p 3000:3000 \ myapp:latest # api can reach db by hostname "db" docker exec api ping db -c 3 docker exec api nslookup db # Inspect the network docker network inspect app-network # Connect a running container to an additional network docker network connect app-network existing-container # Disconnect and remove docker network disconnect app-network existing-container docker network prune -f
Result
Open