Github source code link
Docker Compose
Command
# build with no cache and detail
docker compose build --no-cache --progress plain
# create and run
docker compose create
docker compose start
# delete
docker compose down
docker image rm image-name
Example
Mongo Db
version: "3.8"
services:
mongodb1:
image: mongo:latest
container_name: mongodb1
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: khannedy123
MONGO_INITDB_ROOT_PASSWORD: khannedy123
MONGO_INITDB_DATABASE: admin
volumes:
- "mongo-data1:/data/db"
mongodb-express:
image: mongo-express:latest
container_name: mongodb-express
restart: always
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: khannedy123
ME_CONFIG_MONGODB_ADMINPASSWORD: khannedy123
ME_CONFIG_MONGODB_SERVER: mongodb1
ME_CONFIG_BASICAUTH_USERNAME: root
ME_CONFIG_BASICAUTH_PASSWORD: example
depends_on:
- mongodb1
volumes:
mongo-data1:
name: mongo-data1
mongo-data2:
name: mongo-data2
For Dockerfile
version: "3.8"
services:
node-example:
container_name: node-example
build:
context: "."
dockerfile: Dockerfile
image: "app-node-example:1.0.0"
ports:
- "3000:3000"
Dockerfile
Command
# inspect image
docker image inspect badru/workdir
# logs container
docker container logs workdir
# get into container
docker container exec -i -t workdir /bin/sh
Example
Golang
FROM golang:1.18-alpine
WORKDIR /app/
COPY . /app/
EXPOSE 8080
CMD go run main.go
Node js (no dependency)
FROM node:16-alpine
WORKDIR /app/
COPY . /app/
EXPOSE 3000
CMD node app.js
Node js with dependency
FROM node:16-alpine
WORKDIR /app/
COPY . /app/
EXPOSE 3000
RUN npm install
CMD node app.js
Multi with Golang
FROM golang:1.18-alpine as builder
WORKDIR /app/
COPY . /app/
RUN go build -o main main.go
FROM alpine:3
WORKDIR /app/
COPY --from=builder /app/main /app/
EXPOSE 8080
CMD ./main
Top comments (3)
tes1