Skip to content

Instantly share code, notes, and snippets.

@petegivens
Last active February 26, 2018 23:02
Show Gist options
  • Save petegivens/f4fc9a5c3b33c4535b1337a65f4b0871 to your computer and use it in GitHub Desktop.
Save petegivens/f4fc9a5c3b33c4535b1337a65f4b0871 to your computer and use it in GitHub Desktop.
Docker Overview

Docker

Image VS Container

  • An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.

  • A container is launched by running an image. A container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process).

Container VS Virtual Machine

A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.

Docker Compose

Docker Compose is a tool for running multi-container Docker instances

Using Compose is basically a three-step process:

  1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.

  2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.

  3. Run docker-compose up and Compose starts and runs your entire app.

CLI Reference

docker-compose up: Builds, (re)creates, starts, and attaches to containers for a service.

Flags: --build flag tells Docker to build the images before starting the container. Not totally clear on when this is needed vs when the cached images are okay to use.

docker-compose down: Stops containers and removes containers, networks, volumes, and images created by up.

Questions

I'm still not 100% clear on how multiple containers might discover and interact with one another. I ran docker-compose up on the root directory, then ran yarn dev from applications/CMS and yarn start / yarn start-docker from applications/Gateway, which threw lots of ECONN REFUSED errors. However, I was able to connect to localhost:3000/graphql which I believe is coming from the gateway application, so I'm just not sure how they all interact right now.

@Nathan-Schwartz
Copy link

@petegivens
Bonus CLI command
docker exec -it <container-name> bash will let you run commands inside a container.

You may have gotten ECONN REFUSED if you started CMS before the gateway was all the way up.
The reason is that yarn dev updates the local schema based on what the graphql service is serving. If it was down at the time of the request, it would fail.

CMS looks for the API on localhost:3000, which works because of our port forwarding in docker-compose.yml

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