Docker Learning Note (iv)

Image for post
Image for post
Photo by Derek Oyen on Unsplash

This is a series blogs about Docker and Kubernetes — This is the 4th blog following up to my last one.

In last blog, we will focus on Docker compose file.

Docker compose acts like a CLI tool that helps to start up multiple docker containers at the same time; it helps to specify what images are required, what ports they need to expose, and so on. Common commands exclude:

- docker run my_image
docker-compose up

Replace Dockerfile with docker-compose.yml

A common use case for multiple files is changing a development Compose app for a production-like environment (which may be production, staging or CI). To support these differences, you can split your Compose configuration into a few different files. In the example we have web and tests for dev environment.

version: “3” //version 3 of the tool
stdin_open: true
context: . //the content to build the Dockerfile
dockerfile: //get the name more clear
- “3000:3000”
volumes: //mapping local file to docker container == setting up reference to the local file
- /app/node_modules //make this reserved in container, so this dir won't be overwritten by the copy command below
- .:/app. //map the parent directory /app in the container

As reference, the that is mentioned above:

A more complex but common configure with client, server, worker and nginx:

version: “3”

And the Dockerfiles mentioned above are:

FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]

That’s so much of it. Happy Reading!

🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟 🐬 🐳 🐋🐟

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store