Docker - ayaohsu/Personal-Resources GitHub Wiki

Introduction

Container: A way to package application with all the necessary dependencies and configuration

  • Self-Contained
  • Portability

Public Repo (docker hub): This contains the official and unofficial images of applications/tools you can use

Problems that containers solve:

  • Developers need to install apps and set up configurations themselves

Docker contains layers of components of an image. When you upgrade a version, only different layers are downloaded.

Docker Image vs Docker Container

Image is the actual package. It is the app + services + scripts + config. It is an artifact that can be moved around.
Container is the actual process/environment when the application starts. When it starts, a container environment is created.
Basically it is running vs not-running.

Container vs Virtual Machine

They are both virtualization tools.
Containers virtualize the application layer, while VM virtualizes the kernal layer.

Basic Commands

$ docker pull redis $ docker images
$ docker run redis
$ docker ps
$ docker stop 862386c58c1d
$ docker ps -a (all container even if exited)
$ docker run redis:4.0 (pull the version and run)

Host Port vs Container Port

The host (PC or laptop) has multiple ports available to assign to containers. Each container has to have its own binding host port. However, a 'container port' is the port managed on the container side. This can be the same for different containers.

docker run -p6000:6379 Host port: 6000; Container port: 6379

Debug

$ docker exec -it /bb/bin

  • env
  • exit

Demo Project

Docker can integrate with the following steps:

  • Development
  • Continuous Integration
  • Deployment

Docker Network

$ docker network ls
$ docker network create mongo-network
$ docker run -d \

-p 27017:27017 -e MONGO_INITDO_ROOT_USERNAME=admin
-e MONGO_INITDB_ROOT_PASSWORD=password
--name mongodb
--net mongo-network
mongo

Docker Compose

Start multiple services in .yaml file $ docker-compose -f mongo.yaml up $ docker-compose -f mongo.yaml down

Dockerfile

A blueprint for building images

WORKDIR -> this will be in the virtual environment, not the host
COPY -> executes on the HOST machine so you can copy from host to docker CMD -> run inside the container (["node", "server.js"]). This is the entry point

To build an image on our own: $ docker build -t my-app:1.0 .
$ docker rm (remove a container)
$ docker rmi (remove an image)

⚠️ **GitHub.com Fallback** ⚠️