[docker] basic use of docker

Docker

What is docker

The difference between docker and a virtual machine is that a virtual machine uses virtualization technology to deploy a different operating system on the Host OS using a hypervisor, and then runs an app; this often takes up a lot of hardware resources; however, docker uses the concept of containers , directly combine each app and lib to form a container for use.

We can see that the virtual itself occupies a total of 7G of memory, so we have no way to divide more virtual machines to deploy more applications , but we deploy applications, and we use applications instead of operating systems .

Related Concepts

  • Images
    Images are similar to tarballs, but are "extracts" of discs. To put it simply, before installing the system, you need to use a CD, but after using the virtual CD-ROM, you can directly use the image file to install. The image file cannot be used directly, it needs to be decompressed with tools such as a virtual CD-ROM drive
    ref:
    Computer knowledge: one step to understand the image file

Base use

  • Add permissions for non-root users
    Add the existing user apache to the append group group, docker;
      usermod -a -G apache docker
    

pre-installations

  1. apt-get update

  2. apt-get install vim

  3. install python

    # apt install python-pip	#python 2
     # apt install python3-pip	#python 3
    

    sudo ln -s /usr/bin/pip3 /usr/bin/pip

  4. celery:
    pip install celery==5.2.3

  5. cv2
    apt-get update && apt-get install libgl1
    apt-get install libglib2.0-dev


  • install python

    • docker pull python:3.8
  • docker common commands

    • docker ps -a

    • docker cp 本地文件路径 ID全称:容器路径: file transport.

    • docker run -it --gpus all nvidia/cuda:10.2-base-ubuntu16.04: start a mirror;

      • docker run -i -t --network host --gpus all mot-service:0811 /bin/bash
    • docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

      runoob@runoob:~$ docker commit -a "runoob.com" -m "my apache" a404c6c174a2  mymysql:v1 
      sha256:37af1236adef1544e8886be23010b66577647a40bc02c0885a6600b33ee28057 
      runoob@runoob:~$ docker images mymysql:v1
      REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
      mymysql             v1                  37af1236adef        15 seconds ago      329 MB
      

      -a : The author of the submitted image;
      -c : Use the Dockerfile command to create the image;
      -m : The explanatory text when submitting;
      -p : Pause the container when committing.

    • Mount directory
      docker run -it --network host -v /home/zzzj/Projects/MOT-service-celery:/home/Projects mot-service:v2 /bin/bash
      Caution: When mounting a directory, the local path needs to be specified.

    • Delete container
      docker container prune: delete the stopped container;

    • delete mirror
      docker rmi name

    • import image
      docker load --input face_rec.tar

    • export image
      docker save > nginx.tar nginx:latest

    • docker run/ docker exec
      "docker run" is usually the command used in newly created containers. It's for when you want to create a container when no other containers are running, and you want to start it, and then run a process on it.
      "docker exec" is for when running a command in an existing container. The "docker exec" command is perfect if you already have a running container and want to change it or get something out of it.
      Using docker run to create a new container, then using docker exec to enter the container, and then exiting the container does not cause the container to shut down.

      #run docker background
      docker run -itd --name ubuntu-test ubuntu /bin/bash
      #into a docker
      docker exec -it 243c32535da7 /bin/bash
      
  • Errors:

    • ncclSystemError: System call (e.g. socket, malloc) or external library call failed or device error. It can be also caused by unexpected exit of a remote peer, you can check NCCL
      When docker run, call ipccommunication.
  • ref:

Guess you like

Origin blog.csdn.net/lishijin5421/article/details/127674062