background

Because docker is needed in the project, I will take advantage of the weekend to take a quick look at the basic knowledge of Docker and record the problems encountered in the process


Windows10 Docker environment construction

  • Docker Desktop Windows 10 hub.docker.com/editions/co download address…
  • After the first successful installation, it is possible to open WSL 2 version too low. Run the command directly in CMD:
WSL -- Update # update with one clickCopy the code

Or download the latest version aka.ms/wsl2kernel/

  • Download foreign resources in China and use domestic accelerator services. For Windows docker->Docker Engine (/etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://reg-mirror.qiniu.com/"# accelerator],"insecure-registries": [
    "127.0.0.3:8082 /"If HTTP and HTTPS exist during synchronization, this parameter needs to be set. Generally refers to the private storage service address]}Copy the code

To configure parameters, restart the Docker service. More parameters refer to official recommended configuration docs.docker.com/engine/refe…

After the configuration is complete, view the corresponding configuration and enter the following command:

docker info
Copy the code
  • Note: Because it is run under Git bash under Windows10, not under LUNIX environment, so sometimes the input command is not recognized, you need to add Winpty before the command

Docker basic concepts

  • Docker: virtualization technology at the operating system level. It’s the environment in which the program runs. Easy to create and use containers. It contains three basic concepts: mirroring, capacity, and repository
  • Image: a special file system that provides programs, libraries, resources, configurations, and so on for the container to run
  • Capacity Container: The Container is the entity of the image running. Equivalent to classes and instances in aspect object programming
  • A Repository: a place where images are stored
  • Registry: a service that centrally stores and distributes images. A Docker Registry can contain multiple repositories, and each repository can contain multiple labels, with one image for each label

Docker basic commands

Mirror processing: Docker search helloworld # search helloworld docker pull helloworld # Docker pull < domain name/IP >[: port number] docker pull < domain name/IP >[: port number] docker pull Docker run -it --rm Ubuntu bash # -it interactive terminal --rm container exit after default delete bash using interactive shell command docker image ls # docker images # docker image rm Docker image ls -f sicne= helloworld # delete hello-world docker image ls -f sicne= helloworld To delete the specified mirror, Before docker image rm $(docker image ls -q -f before=hello-world) # Docker load < d: hello.tar.gz # import docker image to docker library container Docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps -a docker ps To clear the message, Docker container prune Docker rm e56933F77A0C # Delete the container number docker container stop < container number > # terminate the corresponding container Docker container Docker run -dit Ubuntu docker run -dit ubuntu Docker attach < container number > is neededexitExit the container default stop. Exec in, exec out doesn't stopCopy the code

Use Dockerfile to customize the image

  • Dockerfile is a text file that contains each instruction, and each instruction builds a layer, so the content of each instruction is to describe how the layer should be built
  • FROM typically specifies the base image
  • The RUN command is executed during the construction phase of the image file, and the execution results are packaged into the image file (multiple RUN commands can exist).
  • The CMD command is executed after the container is started. By default, there is only one CMD command
  • && can be used to concatenate various commands to avoid using too many RUN commands and creating useless layers
  • Docker builds are generally used
  • Dockerignore culling does not need to be passed as a context to the Docker engine
Docker build -t nginx:v1. # Indicates the current directoryCopy the code

Case reference www.ruanyifeng.com/blog/2018/0… Customize the image. It is a little pity that the home network speed is too poor, running to the last step of installation, has not successfully downloaded well.