Sign inSign up

actionanand/docker_communication

By actionanand

•Updated almost 3 years ago

It's all about communication in docker.

Image
0

130

actionanand/docker_communication repository overview

⁠Communication in Docker - Networks / Requests (section 3)

In many application, you'll need more than one container - for two main reasons:

  1. It's considered a good practice to focus each container on one main task(e.g. run a web server, run a database, ...)
  2. It's very hard to configure a Container that does more than one main thing (e.g. run a web server AND a database)

Multi-Container apps are quite common, especially if you're working on real applications.

Often, some of these Containers need to communicate though:

  • either with each other
  • or with the host machine
  • or with the world wide web

⁠Commands used in this project

Here are the commands used in this project

⁠Using docker's DB (docker network)

For this, All the containers should be under the same network

  1. Create a new docker network
docker network create network_name
docker network create mongo-net
  • You can view the existing networks by docker network ls
  • You can remove the unused networks by docker network rm network_name
  • docker network --help is for help related to docker network
  1. Running mongo image with volume and docker network
docker run -d --rm -v mongo-com-vol:/data/db --name mongoCommunication --network mongo-net mongo:7.0
  • -v mongo-com-vol:/data/db is named volume with the name mongo-com-vol
  • You can view the existing volumes by docker volume ls
  • You can remove the unused volume by docker volume rm volume_name
  • docker volume --help is for help related to docker volume
  1. Pulling the project
docker pull actionanand/docker_communication
  1. Running the container with docker network
docker run -d -p 3000:80 --rm --name docker_communication --network mongo-net actionanand/docker_communication
  1. You can open the postman app(or any other similar client) and try the following API end points

    1. GET request for http://localhost:3000/movies

    2. GET request for http://localhost:3000/people

    3. POST request for http://localhost:3000/favorites with the following body as example

      {
        "name": "A New Hope",
        "type": "movie",
        "url": "https://swapi.dev/api/films/1/"
      }
      

      And make sure to keep the type as either movie or character. If you use anything apart from this, error will be thrown from backend

    4. GET request for http://localhost:3000/favorites

Tag summary

Content type

Image

Digest

sha256:b222e9b04…

Size

388.8 MB

Last updated

almost 3 years ago

docker pull actionanand/docker_communication