Skip to content

Instantly share code, notes, and snippets.

@K3ndev
Last active June 15, 2024 15:11
Show Gist options
  • Save K3ndev/62416a27566a8bbc038170009757cfd3 to your computer and use it in GitHub Desktop.
Save K3ndev/62416a27566a8bbc038170009757cfd3 to your computer and use it in GitHub Desktop.

Untitled-2024-04-29-1438(1)

Aspect VirtualBox Docker
Virtualization Type Hardware (Full Virtualization) OS-Level (Containerization)
OS Requirement Each VM requires its own OS Containers share the host OS kernel
Resource Overhead Higher, due to multiple OS instances Lower, due to shared OS kernel
Startup Time Slower, due to full OS boot process Faster, containers start almost instantly
Isolation High, each VM is fully isolated High, but not as complete as VMs
Use Case Running different OSes, legacy software Microservices, application deployment

virtual machine

  1. NAT (Network Address Translation)
    • VMs use the host's IP for internet access.
  2. Bridged Networking
    • VMs connect directly to the physical network, each getting a unique IP.
  3. Host-Only Networking
    • Private network between host and VMs.
  4. Internal Networking
    • VMs only communicate with each other.

docker

Dockerfile

  • FROM: Specifies the base image to build on top of it.
  • WORKDIR: Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it in the Dockerfile.
  • COPY: Copies files or directories from the host machine to the container's filesystem.
  • RUN: Executes a command in the container. It's used to install packages, update software, or any other command needed to set up the environment.
  • EXPOSE: Informs Docker that the container listens on specific network ports at runtime. It does not actually make the ports accessible from the host.
  • ENV: Sets environment variables in the container. These variables can be accessed by processes running inside the container.
  • ARG: Defines variables that users can pass at build-time to the builder with the docker build command using the --build-arg = flag.
  • VOLUME: Creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or other containers.
  • CMD: Specifies the default command to run when a container is started. Only one CMD instruction can be specified in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
  • ENTRYPOINT: Allows you to configure a container that will run as an executable. It allows the container to be run as if it were a binary or script.

  • docker run --rm -ti -v .:/work <image>
    • --rm remove the container after exit is executed
    • -ti for command line
    • -v .:/work for volume

setup db

Start Your PostgreSQL Container

docker run --name postgres -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres

Start the Adminer Container

docker run --name adminer --link postgres:db -p 8080:8080 adminer

format

postgres://<username>:<password>@<host>:<port>

remove hidden container

  • docker ps -a
  • docker stop <1> <2>
  • docker remove <1> <2>

...

docker run -it --rm debian sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment