Skip to content

Instantly share code, notes, and snippets.

@kudaliar032
Last active February 15, 2021 15:12
Show Gist options
  • Save kudaliar032/f3a7ff1f17dbc376510a14c865b78091 to your computer and use it in GitHub Desktop.
Save kudaliar032/f3a7ff1f17dbc376510a14c865b78091 to your computer and use it in GitHub Desktop.
Docker

Docker

Adalah tools yang digunakan untuk menjalankan container

Container

Teknologi yang digunakan untuk menjalankan sebuah aplikasi, dimana dengan container aplikasi akan dibungkus bersama dengan libraries yang dibutuhkan aplikasi tersebut. Sehinga lebih cepat apabila dijalankan dibandingkan dengan virutalization.

Alternative

  • LXC
  • rkt
  • podman

Docker Architect

Docker Daemon

Yang menjalankan dan yang mengatur resource seperti images, containers, networks, dan volumes.

Docker Client

Tools yang digunakan untuk memanage docker daemon dan berintaraksi dengan resource docker.

Docker Registries

Storage untuk menyimpan image-image dari docker.

  • Docker hub
  • GCR
  • ECR
  • GitHub container registry
  • GitLab container registry

Docker Object

Images

Template dari sebuah container

Containers

Runnable docker image

Check docker version

  • docker version
  • docker info
  • sudo systemctl status docker

Docker help

  • docker help
  • docker --help

Images list

  • docker images
  • docker image ls

Containers list

  • docker container ls
  • docker ps
  • docker ps -a

Run a container

  • docker run -it ubuntu
  • docker run -d nginx

Container inspect

  • docker inspect [contaner-name] | grep IPAddress
  • curl [ip-address]
  • docker stop [container-name]

Expose port

  • docker run -d --expose 80 -P nginx
  • curl localhost:[random-port]

  • docker run -d -p 80 nginx
  • curl localhost:[random-port]

  • docker run -d -p 8080:80 nginx
  • curl localhost:8080

Execute command

  • docker run ubuntu ls

  • docker run ubuntu pwd

  • docker run -d nginx
  • docker ps
  • docker exec [container-name] ls /usr/share/nginx/html
  • docker exec -it [container-name] /bin/bash

Pull

docker pull alpine


docker pull ubuntu:20.04

Dockerfile

https://docs.docker.com/engine/reference/builder/

Dockerize Web Server

  • mkdir docker-image
  • cd docker-image
  • vim Dockerfile
FROM ubuntu:18.04
RUN apt update -y && apt install -y nginx
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
  • docker build -t latihan:v1 .
  • docker images
  • docker run -d -p 8080:80 latihan:v1
  • docker ps
  • curl localhost:8080

Dockerize Node.js App

FROM node:12
WORKDIR /app
ADD src/ /app/
RUN npm install
CMD ./bin/www
EXPOSE 3000
  • docker build -t weather-app:v1 .
  • docker images
  • docker run -d -p 3000:3000 weather-app:v1
  • docker ps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment