• Other contents of the series
    1. Docker quickly creates lightweight portable containers
    2. Docker&flask quickly builds service interfaces
    3. Docker and UWSGI high performance WSGI server production deployment requirements
    4. Docker&gunicorn high performance WSGI server production deployment requirements
    5. Docker, Nginx and Gunicorn implement load balancing
    6. Docker&ngxtop and parsing nginx logs in real time
    7. Docker&supervisor monitors your services
    8. Docker and PyInstaller two-step build small volume container
    9. Locust does high concurrency testing on your service
    10. Postman is a popular API debugging tool
    11. Docker + Flask + Gunicorn + Nginx + PyInstaller + Supervisor builds a lightweight service with high concurrency performance

Docker installation

  • This tutorial is based on a Redhat Linux server
  • introduce
    • Docker provides isolated running space for applications:
    • Image as the basis, an image can create multiple containers to facilitate rapid service deployment and migration.
    • Each container contains a unique and complete user environment space, and changes in one container do not affect the operating environment of the other containers;

Online installation

  • Ali Cloud install Docker

    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    Copy the code

  • Start the service

    Switch to user root Run the following commands in sequence: systemctl enable docker # start docker systemctl start docker # restart docker # restart dokcerCopy the code

Offline installation

  • Open the webpage and select the corresponding Docker version
https://download.docker.com/linux/static/stable/x86_64/
Copy the code
  • Upload to server (the version we chose was Docker-rootless – Extras-20.10.5.tgz)
Tar -xvf docker-20.10.5.tgz cp docker/* /usr/bin/dockerd & docker-vCopy the code

Delete a docker

  • Query which docker packages are installed on the current system
    yum list installed | grep docker
    yum remove containerd.io.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64 docker-ce-rootless-extras.x86_64
    docker -v
    Copy the code

Build the mirror

  • Using open Source Images

    Docker Pull Alpine # Is lightweight, but cannot execute python packaged exe docker pull Debian: Bust-Slim # is also smaller in size. You can execute a Python packaged exe fileCopy the code

  • Build your first image

    The specific service building can be described in the next article # Docker&Flask Fast Building service interfaces.

    • Verify the validity of the Flask service
    # flask_test. Py serve we construct flask python3 flask_test. Py wget can start the service - O apirsult. TXT "http://127.0.0.1:2222/test? name=xiaoming&pwd=123Copy the code

    • Build personal Docker image and service validity according to Dockerfile file
    % % writefile Dockerfile FROM python / 3.8 WORKDIR/home/myfirstapi/RUN ln - sf/usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY . . RUN pip install -r requirements.txt -q -i https://pypi.tuna.tsinghua.edu.cn/simple && \ rm -rf /var/cache/apk/* expose 2222 CMD ["python3", "Flask_test.py "] # docker build -t test/ API :1.0. Docker run -d -p 2222:2222 test/ API :1.0 wget -o Apirsult. TXT "http://127.0.0.1:2222/test?name=xiaoming&pwd=123"Copy the code

Common docker commands

  • Basic use, you can use Docker to build containers
    • The basic application of container, involving image and container construction, container view related content.
Docker build -t test/ API :2.0 docker build -t test/ API :2.0 Docker run -d -p 4050/4050 test/ API :2.0 docker run -d -p 4050/4050 test/ API :2.0 Container exec it container-id /bin/bash # Check and stop container docker ps docker stop ontainer-id # Check docker logs -f --tail 100 Container - id or vim/var/lib/docker/containers/container id/container id - json. The log # view ports docker port container - idCopy the code
  • Just walk around and play with the Docker
    • It involves container migration, modification, and data volume related content
Docker cp container-id:/root/test. TXT /root/docker cp /root/container-id :/root/test. TXT Exec container-id ls - LTH docker exec container-id cat file.py # Docker commit -a "my_name" -m "install XXX "container-id image_name # Save docker save -o Docker load --input test.tar # Change the name of the image docker tag [id] [new image name]:[new image tag] # Change the name of the image Docker run - d - p - 4001-4000 the name of the web - v/home/Linux: / home/docker/test/API: 1.0Copy the code
  • We’ve flipped the table. Quickly delete all images and containers
    • Quick stop, remove all containers, mirror
Docker system df # delete all unused data docker system prune -a # stop all processes in docker container-id # delete all containers Docker kill $(docker ps-a-q) # delete all docker rm $(docker ps-a-q) # delete all docker images rmI $(docker images -q)Copy the code