Skip to content

Instantly share code, notes, and snippets.

@kyle-morton
Created August 18, 2020 02:13
Show Gist options
  • Save kyle-morton/f39f7e892179ce1893b00403a786a34d to your computer and use it in GitHub Desktop.
Save kyle-morton/f39f7e892179ce1893b00403a786a34d to your computer and use it in GitHub Desktop.
Docker Container Linking

Container Linking

  • this is very useful if you have an app image that needs to communicate w/ 1 or more other containers (things like a web server, database(s), other app servers, etc)

Linking containers by name (legacy linking)

Steps

  1. Run container w/ a name using cmd line switch docker run -d --name {container-name} {image-name}

  2. Link to running container by name docker run -d -p 5000:5000 --link {other-container-name}:{alias-inside-container} {image-name}

  3. Repeat for additional containers

Container (Bridge) Networks

Creates an isolated network of containers. Containers can access any other container (by name) within the network.

Steps

  1. Create custom bridge network

docker network create --driver bridge {network_name}

  1. Run containers in network (make sure they have their own name)

`docker run -d --net={network_name} --name {container-name} {image-name}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment