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 |
- NAT (Network Address Translation)
- VMs use the host's IP for internet access.
- Bridged Networking
- VMs connect directly to the physical network, each getting a unique IP.
- Host-Only Networking
- Private network between host and VMs.
- Internal Networking
- VMs only communicate with each other.
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
docker run --name postgres -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres
docker run --name adminer --link postgres:db -p 8080:8080 adminer
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