-
Notifications
You must be signed in to change notification settings - Fork 1
Docker setup
Using containers to manage the different portions of the application makes it easier for developers to get started and for deploying to different platforms.
We have Dockerfile's for each section of the app:
- ui-components Storybook
- Public NextJS app in sites/public
- Partner NextJS app in sites/partners
- Backend NestJS app in backend/core
Due to the fact that we're using Yarn workspaces, any dependencies that are shared are created in the top level directory instead of inside the root of the NextJS app. So in order for the Dockerfile to be able to access files from the top level directory, it must sit in the top level directory. backend/core is standalone enough that it doesn't need to have its Dockerfile in the top level directory.
docker-compose is useful for bringing up and connecting all of these separate Docker containers together into a coherent site running locally.
!! Important Note !!
The docker-compose is set up in such a way that only the development stages of the containers are run. This means that you could have a working docker-compose up but still fail if you attempt to deploy the containers. This would mean that there is likely a problem in the production stage of the Dockerfile and to debug, you should start some portion of the containers with docker-compose up <service1> <service2> and then attempt to build and run the container you're debugging by itself. This will ensure that you're running with the production version. Alternatively, we could create a separate docker-compose.yml to use for testing production builds.
Inside the file are definitions and overrides, such as:
- Addressing the containers by name instead of
localhost, e.g.postgres://postgres:5432/bloomfor DATABASE_URL. - Connecting the containers by specifying networks.
- Mounting local volumes into the container for edit/refresh.
- Selecting the appropriate stage of build for the container image.
-
docker-compose up- starts all containers in thedocker-compose.ymlfile. -
docker-compose up <container> <container>- starts only the services explicitly listed as well as any dependencies of those services.- Note: Docker will not show you logs for the dependent containers, only the ones you explicitly list.
-
docker-compose up --build -V- rebuild all containers and remove all anonymous volumes (which are how thenode_modules/directories are mounted in the containers).
-
docker network ls- list all the available docker networks. -
docker build --no-cache- build an image and don't use the cache for intermediate steps.- Can be useful if you are trying to rebuild the
getStaticProps().
- Can be useful if you are trying to rebuild the
-
docker images- view all images docker has built -
docker image prune- prune any unused images; useful for freeing up disk space.
-
docker build -t my-app .- build an image and tag it withmy-appfrom the current directory'sDockerfile. -
docker build -f Dockerfile.sites-public -t public-standalone .- build the sites/public image from Dockerfile.sites-public and tag it with the labelpublic-standalone. -
docker build --network=host -f Dockerfile.sites-public -t public-standalone .- build the sites/public image but use the localhost networking during build time.- Useful if your
getStaticProps()are failing because building the container by itself tries to reach localhost, which does not address your workstation's localhost but addresses the docker container itself.
- Useful if your
-
docker run --env PORT=3000 -p 3000:3000 public-standalone- run the image taggedpublic-standalone, pass in the environment variable PORT, and map the docker container's port 3000 to localhost:3000. -
docker run -it public-standalone /bin/sh- open an interactive shell inside the docker image taggedpublic-standalone. -
docker run --env-file=".env" --network=bloom-detroit_backend backend-core-standalone- run the image taggedbackend-core-standalonewith the environment variables defined in.envand connecting it to the docker networkbloom-detroit_backend.- This is particularly useful if you're testing a standalone image but want to connect it up to some backend containers that you have running via
docker-compose.
- This is particularly useful if you're testing a standalone image but want to connect it up to some backend containers that you have running via
-
docker run --env-file=".env" --network=host backend-core-standalone- run the image taggedbackend-core-standalonebut use the host's networking to resolve DNS.- This is useful in case you want the container to talk to ports on your local machine that are being used by other services not running in a docker container (and thus are not addressable via docker's internal networking).
docker build -f Dockerfile.ui-components -t ui-components .docker run -p 40953:40953 ui-components