1. The image is equivalent to a Java class, and the container is the instance object created by the class. (Easy to be mistaken for an image put into a container)
2. Through the image (which has your software such as the environment in which the app runs, etc.), create the container through the image, and finally the Dockerfile is like an automation script (it is mainly used to create the image we talked about earlier)
3. If you are using vscode, it is highly recommended to install the extension of docker, which will provide syntax detection of dockerfile, code highlighting, auto-completion, etc.
Run is used when creating images (supports shell commands such as pwd, pip, etc.), and CMD is used when running containers
At this point, our automation script Dockerfile is complete
Next we can use docker build to create an image
This "." cannot be omitted. The first call to docker build will be slower, because Docker will download the necessary image files, and then run the instructions in the Dockerfile line by line, but calling it again will be much faster because Docker will cache the previous an operation
This caching operation is also known as layering in Docker, and we won't discuss it here.
After downloading the image, we start a container through docker run . What should be noted here is the -p parameter, which will transfer a certain port on the container
It will map a port on the container to your local host, so that you can access the web application in the container from the host
docker run -p 80:5000 -d my-finance
(The front 80 is the port on our local host, and the back is the port on the container. Don't mess this up)
If nothing else, you can already access the web application in your browser
There will be exciting content in the follow-up comparison about front-end and back-end separation. If you are interested, you can go to the video link in the reference materials to learn.
References