-
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).
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 is a tool for running multi-container Docker instances
Using Compose is basically a three-step process:
-
Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
-
Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
-
Run docker-compose up and Compose starts and runs your entire app.
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.
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.
@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 indocker-compose.yml