file

Docker

The first line of the Docker image starts with an image like Alpine, but how to create the original base image, this article uses a Busybox to create a base image, I believe in this process will have a further understanding of some Docker related concepts.

What is a base image?

Simply put, a base image is an image built without a Dockerfile beginning with From or From Scratch. Alpine, for example, is a tiny Linux image that currently measures around 4M

Docker commonly used image selection

Because Docker images are built on the base image, the more advanced the base image selected, the less low-level work we have to do.

For example, if you’re building an image for a Java application, it’s much easier to choose an OpenJDK image as the base image than a Alpine image.

Docker image official website

Docker official website (Docker Hub) : https://hub.docker.com

Ali Cloud Container Hub: https://dev.aliyun.com

Google image (GCR. IO) : https://console.cloud.google.com/gcr/images/google-containers/GLOBAL (mainly Kubernetes related mirror)

Basic OS image

For example, if you want to start with a Linux OS base image, you can refer to the following table to select the appropriate base image:

Name of the mirror The size of the Usage scenarios
busybox 1.15 MB Temporary test
alpine 4.41 MB Primarily used for testing, but also for production environments
centos 200MB It is mainly used in the production environment, supporting CentOS and Red
ubuntu 81.1 MB It is mainly used in production environments and is commonly used in artificial intelligence computing and enterprise applications
debian 101MB Mainly used in production environment

Build the mirror

Use the command docker build to create a new image. So we need to create a Dockerfile that contains a set of instructions that tell Docker how to build our image. We can choose the right base image to build the image file we need

Dockerfile

The FROM centos: 6.7WORK test
ADD . .
EXPOSE  8080
CMD ['test']
Copy the code

How to Use images

  • Use Docker Run to run images: This is recommended when we are managing an image file individually to run packaged images quickly and easily
  • Using Docker-compose to run image files: This method is recommended when multiple image files need to be managed in a centralized manner

Container entry operation

  • docker exec -it test_image /bin/sh

  • docker exec -it test_image bash

  • docker exec -it test_image sh