Install FastDFS in Docker

Pull the Docker image

#Pull the FastDFS image that contains tracker and storageDocker pull season/fastdfs: 1.2Copy the code

Create a directory for storing files

  • This folder is used to mount files uploaded to FastDFS in Docker
#-p indicates to recursively create a directory that does not exist
mkdir -p /usr/local/fastdfs/tracker/data
mkdir -p /usr/local/fastdfs/storage/data
mkdir -p /usr/local/fastdfs/storage/path
mkdir -p /usr/local/fastdfs/nginx
Copy the code

Create tracker container

Trace server container

docker run -di --name=tracker --net host --restart=always -p 22122:22122 -v \ / usr/local/fastdfs/tracker/data: / fastdfs/tracker/data season/fastdfs: 1.2 the trackerCopy the code

Creating a storage container

Storage server container

docker run -di --name=storage --net host --restart=always -v \ /usr/local/fastdfs/storage/path:/fastdfs/store_path \ -e TRACKER_SERVER = "192.168.20.255:22122" season/fastdfs: 1.2 storageCopy the code

Modify the client.conf configuration file in the tracker container

  • Copy the client. Conf file from the tracker container, modify it, and put it back into the Docker.

docker cp tracker:/etc/fdfs/client.conf /usr/local/fastdfs/tracker/
#Example Change the IP address of the client.conf file
vim /usr/local/fastdfs/tracker/client.conf 

docker cp /usr/local/fastdfs/tracker/client.conf tracker:/etc/fdfs
Copy the code

Configure Nginx

  • Copy the nginx configuration file from the storage container.
docker cp storage:/etc/nginx/conf/nginx.conf /usr/local/fastdfs/nginx
Copy the code
  • Modify the configuration in nginx
vim /usr/local/fastdfs/nginx/nginx.conf


#Modify the contents of the Nginx configuration file
location / {
    root /fastdfs/store_path/data;
    ngx_fastdfs_module;
 }
Copy the code

Create and start the nginx container

docker run -id --name fastdfs_nginx --restart=always -v \ /usr/local/fastdfs/storage/path:/fastdfs/store_path -v \ / usr/local/fastdfs/nginx/nginx. Conf: / etc/nginx/conf/nginx. Conf \ -p 8082:80 - e TRACKER_SERVER = 192.168.20.255:22122 Season/fastdfs: 1.2 nginxCopy the code

test

  • Run the command to enter the tracker container:
docker exec -it tracker bash
Copy the code
  • Create a TXT file:
echo "dangdangdang" > dangdangdang.txt
Copy the code
  • Then upload the dangdang. TXT file to the server using the fdfs_upload_file command:
fdfs_upload_file /etc/fdfs/client.conf dangdangdang.txt
Copy the code