github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/docker/README.md (about)

     1  There are two different ways, or modes, to deploy AIS in Docker containers.
     2  We refer to those ways as [quick-start mode](#quick-start-ais-cluster) and [development mode](#developer-mode).
     3  
     4  [Quick-start mode](#quick-start-ais-cluster) allows for a quick containerized deployment of AIS with minimal setup.
     5  [Development mode](#developer-mode) allows users to test and develop AIS in a more robust containerized environment.
     6  
     7  ## Quick-start AIS Cluster
     8  
     9  Create a containerized deployment of AIStore within seconds.
    10  The minimum requirements to get this working is to have Docker installed.
    11  If you don't have Docker and Docker-Compose installed, please see [Getting started with Docker.](/docs/docker_main.md)
    12  
    13  > For some tests, AWS config and credential files are needed
    14  
    15  1. To quick-start AIStore, run:
    16  
    17      ```console
    18      $ ./deploy_docker.sh -qs
    19      ```
    20  
    21      > The first build may take some time, but subsequent builds will be much faster.
    22  
    23  2. Once it finishes building, you should be inside the AIS container. Run:
    24  
    25      ```console
    26      $ make deploy cli
    27      root@0459b601dcc7$ ais show cluster
    28      ```
    29  
    30  ### Quick-start Example
    31  
    32  If everything went smoothly
    33  
    34  ```console
    35  $ CGO_ENABLED=0 BUCKET=test go test ./tests -v -count=1 -run=smoke
    36  ```
    37  
    38  runs some smoke tests.
    39  
    40  ```console
    41  $ CGO_ENABLED=0 BUCKET=test go test ./tests -v -count=1 -run=bucketname
    42  ```
    43  
    44  Will return you a list of all local and remote buckets.
    45  
    46  > CGO_ENABLED is set to false to enable cross-compiling
    47  
    48  ### Quick-start Configurations
    49  
    50  #### AWS
    51  
    52  Quick-start AIS also works with AWS by enabling users access to their S3 Buckets. To do so, users can specify the location of their AWS credentials by passing in the path. For example,
    53  
    54  ```console
    55  $ ./deploy_docker.sh -qs="~/.aws/"
    56  ```
    57  
    58  ## Developer Mode
    59  
    60  Use the `./deploy_docker.sh` script to deploy AIStore cluster(s) on a single machine. Each cluster can be deployed with one or three networks. The latter case is used to deploy a cluster with separated data and control planes. When deploying multiple clusters, only multiple networks are allowed.
    61  Use the `./stop_docker.sh` script to stop the AIStore cluster(s) that were deployed.
    62  
    63  ## Requirements
    64  
    65  > Install Docker and Docker-Compose prior to deploying a cluster. For setting up Docker services please read [Getting started with Docker.](/docs/docker_main.md)
    66  
    67  [`$GOPATH`](https://go.dev/doc/gopath_code#GOPATH) environment variable must be defined before starting cluster deployment. Docker uses the `$GOPATH/src` directory as a bind mount for the container. The container at start builds new binaries from the current sources.
    68  
    69  For the *i*th cluster, AIStore creates three networks: ais${i}\_public, ais${i}\_internal\_control, and ais${i}\_internal\_data. The latter two are used only if the cluster is deployed with multiple networks (`-m` argument must be passed to the deploy script). It is expected that only AIStore cluster *i* is attached to each these networks. In a multi-cluster configuration, proxy containers of one cluster are connected to the Docker public networks of other clusters to allow for multi-tiering and replication.  In multi-cluster configuration, target containers of one cluster are connected to the Docker public and replication networks of other clusters to allow for multi-tiering and replication.
    70  
    71  ## Deploying a Development Cluster
    72  
    73  Run `./deploy_docker.sh` without arguments if you want to deploy a cluster in interactive mode.
    74  The script will ask you for a number of configuration parameters and deploy AIS accordingly:
    75  
    76  ```console
    77  $ ./deploy_docker.sh
    78  ```
    79  
    80  Be sure that the AWS credentials and configuration files are located outside of the script directory.
    81  The script copies AWS credentials and configuration from the provided location to `/tmp/docker_ais/aws.env` and passes this file to each container.
    82  
    83  To deploy a cluster in 'silent' mode use the following options (if any of them are not set, then the script switches to interactive mode and asks for the missing configuration parameters):
    84  
    85  * `-c=NUM` or `--cluster=NUM`               : where NUM is the number of clusters
    86  * `-d=NUM` or `--directories=NUM`           : where NUM is the number of local cache directories
    87  * `-f=LIST` or `--filesystems=LIST`         : where LIST is a comma separated list of filesystems
    88  * `-h` or `--help`                          : show usage
    89  * `-l` or `--last`                          : redeploy using the arguments from the last AIS Docker deployment
    90  * `-m` or `--multi`                         : use multiple networks
    91  * `-p=NUM` or `--proxy=NUM`                 : where NUM is the number of proxies
    92  * `-s` or `--single`                        : use a single network
    93  * `-t=NUM` or `--target=NUM`                : where NUM is the number of targets
    94  * `-qs=AWS_DIR` or `--quickstart=AWS_DIR`   : deploys a quickstart version of AIS
    95  * `-nocloud`                                : to deploy AIS without any backend provider
    96  * `-grafana`                                : starts Graphite and Grafana (can be accessed at [localhost:3000](http://localhost:3000)) for displaying metrics
    97  
    98  Note:
    99  * If the `-f` or `--filesystems` flag is used, the `-d` or `--directories` flag is disabled and vice-versa
   100  * If the `-s` or `--single` and `-m` or `--multi` flag are used, then multiple networks will take precedence
   101  * Be sure that the aws credentials and configuration files are located outside of the script directory. The script copies AWS credentials and configuration from the provided location to `/tmp/docker_ais/aws.env` and passes this file to each container.
   102  
   103  Please see [main AIStore README](/docs/configuration.md) for more information about testing mode.
   104  
   105  Example Usage:
   106  
   107  ```console
   108  $ ./deploy_docker.sh -p=3 -t=4 -d=2 -c=1
   109  ```
   110  
   111  The command deploys a single cluster with 3 proxies, 4 targets and 2 local cache directories using AWS in normal mode.
   112  
   113  ### Deploying Multiple Clusters
   114  
   115  When deploying multi-cluster configurations, each cluster will have the same number of proxies and targets. Each container name will be of this format: ais${i}\_${target,proxy}\_${j}. Where *i* denotes the cluster number and *j* denotes the *j*th daemon of type target or proxy.
   116  
   117  Example:
   118  
   119  ```console
   120  $ ./deploy_docker.sh -p=3 -t=3 -d=2 -c=3
   121  ```
   122  
   123  The command deploys three clusters, each with 3 proxies, 3 targets and 2 local directories in normal mode.
   124  
   125  ## Restarting a Cluster
   126  
   127  Running the same command that you used to deploy AIS using Docker stops the running cluster and deploys a new AIS configuration from scratch (including multi-cluster configurations). It results in a fresh cluster(s) with all containers and networks rebuilt. Either run the previous deployment command (supply the same command arguments) or use the following command to redeploy using the arguments from the last AIS Docker deployment:
   128  
   129  ```console
   130  $ ./deploy_docker.sh -l
   131  ```
   132  
   133  NOTE: The deploy script saves configuration parameters to `/tmp/docker_ais/deploy.env` each time before deploying. If this file doesn't exist or gets deleted, the command won't work.
   134  
   135  ## Stopping a Cluster
   136  
   137  To stop the cluster, run one of the following scripts:
   138  
   139  ```console
   140  # To stop the last deployed Docker configuration
   141  $ ./stop_docker.sh -l
   142  ```
   143  
   144  NOTE: This command uses the saved configuration parameters in `/tmp/docker_ais/deploy.env` to determine how to stop AIS. If this file doesn't exist or gets deleted, the command won't work.
   145  
   146  ```console
   147  # If a single network AIS configuration is currently deployed
   148  $ ./stop_docker.sh -s
   149  ```
   150  
   151  ```console
   152  # If a multi network AIS configuration is currently deployed
   153  $ ./stop_docker.sh -m
   154  ```
   155  
   156  ```console
   157  # To stop a multiple cluster configuration of AIS that is currently deployed, where NUM_CLUSTERS >= 1
   158  $ ./stop_docker.sh -c=NUM_CLUSTERS
   159  ```
   160  
   161  These commands stop all containers (even stopped and dead ones), and remove Docker networks used by AIS. Refer to the stop_docker.sh script for more details about its usage.
   162  
   163  ## Viewing the Local Filesystem of a Container
   164  
   165  The Docker-Compose file is currently set to mount the `/tmp/ais/${i}/${hostname}` directory, where *i* is the cluster number and *hostname* is hostname of container, to `/tmp/ais` inside the container.
   166  Thus, to see the `/tmp/ais` folder of container `ais${i}\_${target,proxy}\_${j}` obtain the hostname of given container and navigate to `/tmp/ais/${i}/${hostname}` directory on your local machine.
   167  
   168  ## Extra configuration
   169  
   170  It is possible that default settings do not work in specific cases, e.g, default networks cannot be used by AIStore container (default is `172.50.0.0/24` subnet). To fix this you can tune up variables in [deployment script](/deploy/dev/docker/deploy_docker.sh).
   171  
   172  Useful script variables:
   173  
   174  | Variable | Default value | Description |
   175  |---|---|---|
   176  | PUB_NET | 172.50.0 | Public network (data plane for multiple networks case) |
   177  | INT_CONTROL_NET | 172.51.0 | Internal network (control plane for multiple networks case) |
   178  | INT_DATA_NET | 172.52.0 | Internal network (data plane for multiple networks case) |
   179  | PORT | 51080 | HTTP port for public API |
   180  | PORT_INTRA_CONTROL | 9080 | HTTP port for internal control plane API (for multiple networks case) |
   181  | PORT_INTRA_DATA | 10080 | HTTP port for internal data plane API (for multiple networks case) |
   182  | TEST_FSPATH_ROOT | `/tmp/ais/` | the base directory for directories used in testing mode(option `-l` is set). All testing directories are located inside TESTFSPATHROOT and have short names 0, 1, 2 etc. |
   183  
   184  ## Running tests in Docker environment
   185  
   186  Tests are started in the same way as it is done for regular cluster:
   187  
   188  ```console
   189  $ BUCKET=vlocal go test -v ./tests -count 1 -p 1 -timeout 1h
   190  ```
   191  
   192  > The above command assumes that you're in the `aistore/ais` directory
   193  
   194  Tests detect the Docker cluster and use primary URL "http://172.50.0.2:51080" (see `PUB_NET` variable). If `PUB_NET` or `PORT` variable is changed or original primary is stopped or deleted then tests require extra argument that points to an existing proxy, preferably the current primary one:
   195  
   196  ```console
   197  $ BUCKET=vlocal go test -v ./tests -count 1 -p 1 -timeout 1h -url=http://172.51.0.7:51080
   198  ```
   199  
   200  **NOTE:** Some tests require a minimum number of targets or proxies. Also, due to Docker permissions, you might have to run tests with `sudo` too.
   201  
   202  ## Utility Scripts
   203  
   204  ### `logs.sh`
   205  
   206  To quickly view the logs of all running containers, use the following command:
   207  
   208  ```console
   209  $ ./logs.sh -d
   210  ```
   211  
   212  To view the logs of a specific container, use the following command:
   213  
   214  ```console
   215  $ ./logs.sh -c=container_name -t=a
   216  ```
   217  
   218  Refer to the `logs.sh` script for more details about its usage.
   219  
   220  ### `get_ip_addresses.sh`
   221  
   222  If you'd want to quickly get IP addresses of all running containers, execute the following:
   223  
   224  ```console
   225  $ ./get_ip_addresses.sh
   226  ```
   227  
   228  > The default port numbers will be `51080`, `9080`, and `10080` respectively for the **public**, **intra-control** and **intra-data** networks.
   229  
   230  ### Prune docker
   231  
   232  To prune old docker containers, images and networks you can use:
   233  
   234  ```console
   235  $ docker kill $(docker ps -q) # in case you want to kill ALL containers
   236  $ docker system prune -f
   237  ```
   238  
   239  ### Accessing These Scripts From Anywhere
   240  
   241  Add the following to the end of your `~/.profile`:
   242  
   243  ```bash
   244  if [ -d "$GOPATH/src/github.com/NVIDIA/aistore/deploy/dev/docker" ] ; then
   245    PATH="$PATH:$GOPATH/src/github.com/NVIDIA/aistore/deploy/dev/docker"
   246  fi
   247  ```
   248  
   249  After that, execute the following to update your $PATH variable:
   250  
   251  ```console
   252  $ source ~/.profile
   253  ```
   254  
   255  Then, you can just execute the script name from any working directory. Example:
   256  
   257  ```console
   258  $ container_logs.sh CONTAINER_NAME
   259  ```
   260  
   261  ## Limitations
   262  
   263  Certain tests require the ability to modify files/directories or set extended attributes(xattrs) directly onto the filesystem of a container. These tests are currently skipped when using Docker because of Docker's write protection of container volumes.