[Django project is fresh every day] Install Docker Desktop and FastDFS (interaction with python still fails, does anyone encounter the same problem as me?)

Environment: Win10 Professional Edition, find another tutorial for the Home Edition

1. Install docker desktop

Enter the URL and click here to install it directly. There is nothing to pay attention to. When you open it, wsl2 is not installed, just follow the prompts to install it.
insert image description here

After the installation is complete, the image configuration is completed. When pulling the image, you can hurry up and add a few more. Click Settings to select docker engine
insert image description here
insert image description here
and add the following in the box on the right

"registry-mirrors": [
    "https://xxxxx.mirror.aliyuncs.com/", # 这是阿里云下的镜像地址
    "https://docker.mirrors.ustc.edu.cn/",
    "http://hub-mirror.c.163.com/"
  ]

By the way, the lower right corner must always be green during this period, so that docker can be considered a normal startup.
insert image description here
2. Pull the image and let the image run

Reference: fresh every day - readme file in django2.2 version, note that docker desktop needs to be opened during the whole process.

Win+e, enter cmd, enter the command line tool, enter the following command, you need to wait patiently, try a few more times, all pull complete will work.

docker pull pad0y/fdfs:v3

After pulling, it will be displayed in the image
insert image description here
Enter the following command to make the image run

docker run -d --name fdfs\
    -p 8888:8888 \
    -p 22122:22122 \
    -p 23000:23000 \
    -e TZ=Asia/Shanghai \
    -e NET_VAR=eth0 \
    -e MASTER_IP=xxx\ # 这里的ip地址是本机的ip地址
    -v /mnt/fdfs:/var/local/fdfs \
    pad0y/fdfs:v3

If it runs successfully, you will see that the front of the fdfs container turns green
insert image description here
. Check whether the current service is running normally. Enter the command line and
insert image description here
enter ps aux | grep fdfs. The current storage and tracker start normally.
insert image description here
3. Test whether the fdfs container is installed successfully

First check the container id, which will be used for uploading later, enter the following command on the command line

docker ps -a

b4efa4da4c85 is the container id
insert image description here
test upload of fdfs. First, transfer the test picture to the container. The front is the picture path of the machine (the default is the C drive, you can also write "D:/xxxx" to use the path of your own picture), and the back is Container id: target address
My address is c:/
insert image description here

PS C:\Users\DUE> docker cp /xiao.jpg b4efa4da4c85:/etc/fdfs/

Go back to the command line of fdfs, execute the following command to upload the file, and return group1xxxx means the upload is successful!

cd /etc/fdfs  # 进入/etc/fdfs目录
/etc/fdfs # fdfs_upload_file /etc/fdfs/client.conf /etc/fdfs/xiao.jpg  # 上传文件
group1/M00/00/00/rBEAAWJJbjqAZXtGAACCu0eyKfE255.jpg  

To be on the safe side, enter the image address in the browser to test it. It can be accessed, that is, the upload is successful
insert image description here
4. Fdfs interacts with python

Python version: 3.7 Download it
first fdfs_client-py-master.zip, find this in the courseware (there are a lot of comments in station b), then modify it according to the link, the comment, and then find the directory where setup.py is located, and enter cmd in the address bar Enter the command line, enter in the command linepython setup.py install

What you get after finishing is an egg file, don’t worry about it, just use it directly
Reference: Installation problem of fdfs_client module used when using django under windows

Open pythonIDE, guide the package, choose a path to put your own client.conf, and upload

>>> from fdfs_client.client import Fdfs_client
>>> client = Fdfs_client('D:/Program Files/FastDFS/client.conf')
>>> ret = client.upload_by_filename('D:/pictures/xiao.jpg')

Then it became like this, and then there is no more, this is the result of my two days of research, can anyone help me?

I saw an article that seems to be similar to my problem, but the operating system is different, and this method cannot be used to solve it.
Reference: docker installation fastdfs encounters storage IP address mapping host address problem
insert image description here
Finally, I have been looking for bugs these days. I also found a lot of useful commands, maybe you can use it too.

1. Modify the image save path (make sure the wsl application has exited)

C:\Users\DUE>wsl --list -v
  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

Export the image file, don't forget the colon!

C:\Users\DUE>wsl --export docker-desktop-data "D:\Program Files\DockerDesktop\docker-desktop-data.tar"

C:\Users\DUE>wsl --export docker-desktop "D:\Program Files\DockerDesktop\docker-desktop.tar"

unregister subsystem

C:\Users\DUE>wsl --unregister docker-desktop-data
正在注销...

C:\Users\DUE>wsl --unregister docker-desktop
正在注销...

Re-import, the front is the location you want to install, and the back is the location of the compressed package you need to use

C:\Users\DUE>wsl --import docker-desktop "D:\Program Files\DockerDesktop\docker-desktop" "D:\Program Files\DockerDesktop\docker-desktop.tar" --version 2

C:\Users\DUE>wsl --import docker-desktop-data "D:\Program Files\DockerDesktop\docker-desktop-data" "D:\Program Files\DockerDesktop\docker-desktop-data.tar" --version 2

2. View and kill the process

C:\Users\DUE>netstat -aon|findstr "22122"  # 这个是端口号
  TCP    192.168.3.25:54290     192.168.3.25:22122     SYN_SENT        14876
  TCP    192.168.3.25:54291     192.168.3.25:22122     SYN_SENT        14876

C:\Users\DUE>tasklist |findstr "14876"  # 这个是进程号

3. Commands for editing files in linux system

EDIT: vi + filename

The command method of saving and exiting after editing

    1. Esc+:+wq+回车(w是write,q是quit)
    
    2. Esc+:+x+回车(x=wq)

    3. Esc+shift+zz 

    4. Esc+ZZ(在大写开启下)

If you entered the editor, but did not make any changes, the save and exit commands are as follows:

Esc+:+q+Enter

The command to exit without saving: z
is transferred from: Four ways to save and exit after editing in linux system

Guess you like

Origin blog.csdn.net/xiaoluobotm/article/details/123911969