Emran Ul Hadi
Love to share
Run Anything Anywhere
Docker Engine
Docker Hub
1. Docker Daemon
2. Docker CLI
Container is a run time instance of a docker image
FROM | Image name after the keyword which to be a base image of yours. ex> FROM Nginx |
---|---|
ENV | Environment variables for the image. i.e: NODE_ENV |
WORKDIR | Define the working directory |
RUN | Will executed when we `build` |
EXPOSE | Port to be exposed to the host |
VOLUME | Define shared volumes |
CMD | Will executed when `docker run` |
# SAMPLE Dockerfile
FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# Medium size Dockerfile
FROM node:10.15.3 as build-stage
RUN apt-get update && apt-get install -y jq python
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile --registry https://custom-registry
COPY . .
RUN yarn build
# Generate & Upload sourcemaps
RUN chmod 755 upload-sourcemap.sh
RUN ./upload-sourcemap.sh
# production stage
FROM nginx as production-stage
RUN rm /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx-conf/default.conf /etc/nginx/conf.d/
# Remove sourcemap from final image
RUN rm -rf /usr/share/nginx/html/js/*.map
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Manage multiple containers/services at once
version: "2"
services:
redis:
image: redis
container_name: redis
ports:
- "6379:6379"
bifrost:
command: yarn dev -- -L
links:
- redis
environment:
- NODE_ENV=development
- REDIS_URL=redis://redis
Shared files between containers
NOTE: Took all the image in this slides taken from online
H
A
V
E
A
N
Y
By Emran Ul Hadi
Docker is a lightweight virtual machine.