카테고리 없음

What is Docker?

경걍 2025. 4. 29. 21:50
반응형

About Docker

Why use Docker? : Create Container

Problems before using Docker : Development of source code build, compilation, testing, etc., often leads to unexpected problems depending on the hardware environment.

How Docker solved the problems : Developers package applications with images that can run in an isolated environment called containers.

What is Image in Docker : It's made from a setup file that contains everything you need to run an application (code, library, system tools, runtime, etc.). This image ensures that it runs equally in any environment.

 

Virtual Machine vs Container

  Virtual Machine Container
Virtualizes hardware OS Kernel
Runs on Hypervisor Container Runtime
Operating System Each VM requires an independent OS Shares the host system's OS kernel
Boot Time Requires OS boot time (relatively slower) No OS boot required (very fast)
Security No direct impact on other applications on the host system Potential security risks if misconfigured due to shared resources

 

Container structure

The container has namespaces and control groups.

 

What Container Namespaces Do

These namespaces make each running application inside a container think it has its own separate set of important system things. 

 

What Control Groups (cgroups) Do

These are like rules that control how much of the actual computer hardware (like CPU power, network speed, disk access, and memory) each container can use.

 

The merits of the Docker

  • Easy Environment Setup: Container environments can be easily built using Dockerfiles.
  • Easy Image Sharing: Application images can be easily shared via Docker Hub.
  • Easy Container Management: Containers can be created and run easily and quickly using the Docker CLI.

 

Docker Commands 

 

Build(Create) image

docker build -t {image name(tag)} -f {file} .

docker build -t our-web-server -f web-server.Dockerfile .

 

The "." signifies that the Dockerfile and all the context files needed for the image build are located in the current working directory. In other words, it specifies the file location

 

Check images 

docker images

 

 

Delete image 

docker rmi -f {Image ID} 

docker rmi -f 9721

 

Create Container : only create

docker container create {container name}:{tag}

docker container create hello-world:linux

 

Start Container (after create)

docker container start {container name | container ID}

docker container start hello-world

 

Check Container logs

docker logs {container name}

docker logs our-web-server

 

Run Container : create and start 

docker run {image name}
docker run -t {image name} # -t: chat container using terminal
docker run -d {image name} # -d: run background
docker run --name {container name} {image name} # --name : set container name
docker run -p {external port}:{internal port} {image name} # set port 
docker run -v "{external volumn location}:{internal volumn location}" {image name} # set volumn

 

Check containers 

docker ps
docker ps -a
docker ps -al



Delete Container

docker rm -f {container name}

docker rm -f website



반응형