Skip to content

Instantly share code, notes, and snippets.

@adsr303
Last active August 8, 2019 22:11
Show Gist options
  • Save adsr303/e45682c5997d6bb8c1454612248d6526 to your computer and use it in GitHub Desktop.
Save adsr303/e45682c5997d6bb8c1454612248d6526 to your computer and use it in GitHub Desktop.
Connect two Docker containers using networking

Connect two Docker containers using network

Oversimplified HOWTO based on the Docker networking tutorial.

Create a user-defined bridge network

docker network create --driver bridge redis-net

Start our Redis database

docker run --name redis -d --network redis-net redis

Start our web app

We assume that it wants to connect to a Redis server named redis, for example the app used in the official Docker tutorial.

docker run --name webapp -p 4000:80 --network redis-net our-web-app-that-uses-redis

This runs until Ctrl-C.

Stop the Redis database

docker stop redis

Cleanup

docker container rm redis webapp
docker network rm redis-net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment