Skip to content

Instantly share code, notes, and snippets.

@robertorodriguez12
Last active October 21, 2021 20:56
Show Gist options
  • Save robertorodriguez12/29376403908a9f8a24ec447a189bb49a to your computer and use it in GitHub Desktop.
Save robertorodriguez12/29376403908a9f8a24ec447a189bb49a to your computer and use it in GitHub Desktop.

Steps to allow mykotis container to communicate with showcase-admin container, Docker for MacOS


DO NOT COMMIT/PUSH THESE CHANGES UNLESS TOLD OTHERWISE

Steps to setup local network

  1. Open secrets.yml in mykotis and showcase-admin

mykotis secrets.yml

    mykotis_api_key: '<random 10-20 digit key of your choosing>'
    showcase_admin_hmac_key: '<hmac key from showcase-admin>'

showcase-admin secrets.yml

    hmac_key: '<random 10-20 digit key of your choosing>'
    mykotis_api_key: '<api key from mykotis>'
  1. Open the docker-compose.yml file in showcase-admin and make the following changes to create a network
  version: "3.8"
  
  services:
    app:
      build:
        ...
      depends_on:
        ...
       ports:
        ...
       networks:
        - <enter the name of the network to be created (ex. showcase_network)>
       volumes:
        ...
        
    database:
      image:
      volumes:
        ...
      networks:
        - <network name entered above>
    
    redis:
      image:
      networks:
        - <name of network entered above>
        
 volumes:
  db_data:
  node_modules:
  bundle_path:
 networks:
  <name of network entered above>:
      
  1. Open a terminal window outside of VSCodeand run docker network ls and find the name of the network that is created
    • By default the name of your new network is <project_name>_<network_name_from_compose_file>
      • example: showcase-admin_showcase_network
  2. Open the docker-compose.yml file in mykotis and make the following adjustments to connect this container to the new network
version: "3.8"

services:
  app:
    build:
      ...
      ...
    depends_on:
      ...
    ports:
      ...
    networks:
      - <name of the network created (ex. showcase-admin_showcase_network)>
    volumes:
      ...
      ...
      ...
    env_file:
    environment:
      ...
      ...

  database:
    image: ...
    volumes:
      ...
    networks:
      - <name of network created>
    environment:
      ...

volumes:
  db_data:
  node_modules:
  bundle_path:
networks:
  <name of network created>:
    external: true
  1. In the terminal outside of VSCode run docker network inspect <network name> to verify that your containers are present within the network.
  2. In the terminal outside of VSCode run docker ps to get a list of the runnint containers on your machine, save the names of the following containers in a note for later use.
    • You will need the container names of mykotis-app and database
      • Example: mykotis_app_1 / mykotis_database_1
    • You will also need the names of showcase-admin-app and database
  3. Open your development.rb file within mykotis and showcase-admin
    • In mykotis make the following changes
      • Comment out config.kotis_api_uri = "http://localhost:3000/api"
      • Add a new line config.kotis_api_uri = "http://app:3000/api"
      • Add a new line config.hosts = ["app", "<my kotis container name>", "localhost"]
    • In showcase-admin make the following changes
      • Add a new line config.hosts = ["app", "<showcase-admin container name>", "localhost"]
  4. Open database.yml within mykotis and showcase-admin
    • In mykotis make the following changes
      • Comment out host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
      • Add a new line `host: <%= ' || 'localhost' %>
    • In showcase-admin make the following changes
      • Comment out host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
      • Add a new line host: <%= <'showcase-admin database container name> || 'localhost' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment