Docker

Amal Adiguna
HappyFresh Fleet Tracker
2 min readNov 15, 2019

Docker is a containerized deployment system, what does that mean you ask? Remember that article about the three types of environments? The whole “your system is not your client’s system not your customer’s system”? Well now your system can be your client’s system your customer’s system.

Docker is a Linux container that deploys your program and all the dependencies that the deployed program depends on. Dependencies can only be used in the context of the whatever program the docker contains so it doesn’t create errors.

How it works

Docker works by having a daemon (constantly running background process) to handle actions related to containers like docker pull or docker run. The daemon looks for these commands from the CLI/REST API’s. Docker images are individual containers that, can be used as a template for docker images.

How we use it

Docker Compose is used to run multi-container docker apps, with its yaml files being used as config. Once these config files are acknowledged it is then used to create the services and start it.

First, we gotta declare what our environment is going to be like. In HappyFresh, we declare these things in DockerFile. We imagine everyone else would be doing the same. As an example, here is our frontend dockerfile.

ROM node:12.10.0-buster as build
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install --silent
RUN npm install react-scripts -g --silent
COPY . /usr/src/app
RUN npm run build
FROM nginx:1.17.3-alpine
COPY --from=build /usr/src/app/build /var/www
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
ENTRYPOINT ["nginx","-g","daemon off;"]

Second, you gotta define the services that you’re gonna need. Which images, which networks, etc. Here is our docker-compose.yml. This is ours:

version: '3'
services:
dev-tracker-be:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/dev/backend:latest
expose:
- '8080'
networks:
- dev-network
dev-tracker-fe:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/dev/frontend:latest
expose:
- '80'
networks:
- dev-network
stag-tracker-be:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/stag/backend:latest
environment:
PORT: 8080 # for placeholder image
WORLD: stagingBE
expose:
- '8080'
networks:
- stag-network
stag-tracker-fe:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/stag/frontend:latest
environment:
PORT: 80
WORLD: stagingFE
expose:
- '80'
networks:
- stag-network
prod-tracker-be:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/prod/backend:latest
environment:
PORT: 8080
WORLD: prodBE
expose:
- '8080'
networks:
- prod-network
prod-tracker-fe:
image: registry-itprojectki.cs.ui.ac.id/itp2019_1/prod/frontend:latest
environment:
PORT: 80
WORLD: prodFE
expose:
- '80'
networks:
- prod-network
db:
image: mysql:8
restart: always
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: SET_PASSWORD_HERE
volumes:
- /var/lib/mysql:/var/lib/mysql
networks:
- dev-network
- stag-network
- prod-network
proxy:
image: nginx:latest
ports:
- '88:88'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
networks:
- dev-network
- stag-network
- prod-network
networks:
dev-network:
stag-network:
prod-network:

Third, run docker-compose up to acknowledge all these changes and would start and run the application. Many things aren’t defined yet (such as staging and production environment).

Software deployment architecture time.

--

--