Previously, my work platform involved using development, testing, and production environments. Docker is relatively new to me. As I also held a system administrator role, the characterization of Docker as "lightweight and simple" by supporters in the programming development community left me puzzled for a while. Here's a brief explanation of the differences between VMs, Docker, and Virtual Desktops as I understand them.
The platforms most people commonly interact with are standalone systems, which typically include Windows, Mac, Android, and iOS. In the early Unix era, the system architecture consisted of a Host and Terminals. Terminals are lightweight systems with basic functions, which can also be seen today in devices like the Raspberry Pi.
When work requires several systems to perform different tasks, having a separate hardware device for each can be wasteful. This led to the development of Hypervisor and VM (Virtual Machine) architectures.Creating a Docker Image
Example: Create a container that reads user input.
Operational:
docker pull alpine
ducker run -it --name testInput alpine /bin/ash
apk add python3 py3-pip ln -sf python3 /usr/bin/python
vi /home/printInput.py
(exit docker: ctrl+p , ctrl+q )
docker container ls
docker commit 0340edf99261 atfuture7/testinput
docker run -it -rm atfuture7/testinput python3 /home/printInput.py
ref:
https://docs.docker.com/engine/reference/run/
Programmatic:
Running Docker initialization in a new directory.
docker init
Next, a guided process will assist in creating basic data. I chose the "Other option" as a skeleton.
Other - general purpose starting point for containerizing your application
After initialization, Docker creates 4 basic files.
The current version recommends using Compose to combine different resources.
docker compose up --build
Here, I'll explain a simplified Dockerfile, primarily aimed at customizing images.
docker build -t testinupt2 .
The Dockerfile modifies the inherited image and can be divided into different stages.
ref: https://docs.docker.com/build/building/multi-stage/
DOCKER_BUILDKIT determines whether to use BuildKit.
FROM alpine:latest as base FROM base as build FROM base AS final
Modify the build stage to execute a Python script.
docker build --target build -t atfuture7/testinupt2 .
docker run -it -rm atfuture7/testinput2
Running the new image.
Since the entrypoint is defined in the Dockerfile, there's no need to specify a run command when executing the image.
docker run -it atfuture7/testinput2
My sample in GitHub: https://github.com/atfuture7/testcode/tree/master/docker/01_docker_skeleton
Comments
Post a Comment