WEB Backend Service Day 21 - Project Day 1

Posted by Crazy-D on Mon, 16 Sep 2019 04:11:21 +0200

WEB Backend Service Day 21 - Project Day 1

1. Build a project team development platform

II. Basic usage of Docker and Quick Deployment Projects

2.1 Basic Description

Mainstream Development Model: DevOps Development as Operations Maintenance

Docker is based on container technology (virtual technology), including Docker warehouse, mirror, container.When the docker.io installation is complete, there are two processes, Client and Server (daemon), by default.A mirror can run multiple times, each time producing a container subprocess.

apt install docker.io

2.2 Common Commands

  • docker version
  • docker search mirror name
  • docker pull mirror full name
  • docker images view all local mirrors
root@xpy903:/home/disen# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              f7302e4ab3a8        3 weeks ago         98.2MB
  • docker run boot image

Run mirror synchronously

docker run --name redis1 redis

ctrl+C Exit

Run in the background and map ports

docker run  -dit --name redis2 -p 6377:6379  redis 

View all container processes

docker ps -a
root@xpy903:/home/disen# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                     PORTS                    NAMES
68f84c03bbd2        redis               "docker-entrypoint.s..."   About a minute ago   Up About a minute          0.0.0.0:6377->6379/tcp   redis2
c1a00d5f8dbb        redis               "docker-entrypoint.s..."   7 minutes ago        Exited (0) 6 minutes ago                            redis1

Delete Container

docker rm redis1

Stop container process

docker stop redis1

Start Container Process

docker start redis1

delete mirror

docker rmi mirror name or mirror ID

Python Test Connection Code

from redis import Redis

from sys import argv


config = {
   'host': '10.36.174.32',
   'port': argv[1],
   'db': 2
}

client = Redis(**config)

print('Redis Connection Successful! %s' % str(config))

The above is the test_conn.py file, run the script:

python test_conn.py 6377

Exercise Tasks:

docker deploys mysql and writes a test program for msyql.

Note: Running the mirror specifies the password of the root via the -e parameter

docker run -itd -p 3306:3306 --name master -e MYSQL_ROOT_PASSWORD=root mysql

Enter Container

docker exec redis1 ls

The above command executes only the redis1 container to view the files in the working directory of the current container, and -it can be used to enter the container.

docker exec -it redis1 /bin/sh  

Usage of 2.3 Dockerfile

FROM ubuntu-dev:latest
MAINTAINER disen 610039018@qq.com
WORKDIR /usr/src
RUN apt update
RUN apt install cron
RUN git clone https://github.com/xpy903/OneGuyAPI.git
WORKDIR /usr/src/OneGuyAPI
RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
RUN chmod +x auto_down.sh
RUN crontab auto_down.cron
CMD python3 manage.py runserver 0:80

Generate Mirror

Go to the directory where the Dockerfile is located and execute the following command

docker build -t oneguy:1.0 .

Export Import Mirror

Save the image to disk

docker save  -o ~/project.tar  oneguy:1.0  

Load a mirrored compressed file from disk

docker load --input ~/tag.tar

or

docker load < ~/tag.tar 

When the loaded image has no name and tag, you can use docker tag to rename the image ID

docker tag 57165c7f4a35  onebuy:latest 

3. Selection and Analysis of Projects

4. Explanation of Data Model Design

5. Project Daily Requirements

Topics: Docker Redis Python MySQL