Public Repository

Last pushed: a year ago
Short Description
Image for the Random Quotes .NET Core Web API Exercise.
Full Description

Supported Tags

The available version of cycprime/quotesapi are:

  • QuotesAPI version 0.1.0 (tag: 0.1 as well as latest)

Dockerfile

The Dockerfile and sample configurations are available under cycprime/QuotesAPI GitHub repo.

To Use the quotesapi Image

The QuotesAPI image is meant to be used in conjunction with the cycprime/QuotesAPI_MySQL image.

Before starting up a container for the QuotesAPI image, a network needs to be configured so that both QuotesAPI_MySQL container and the QuotesAPI container can communicate with one another. The QuotesAPI_MySQL container will house the database for the QuotesAPI, while QuotesAPI will provide the application interface where clients can access via api calls to retrieve quotes from the database.

To set up a network for both containers, do the following:

docker network create --driver bridge \
                      --gateway <gateway_ipv4_ipv6_dotted_decimal> \
                      --subnet <network_segment_in_CIDR_format> \
                      --opt "com.docker.network.bridge.name"="<interface_name>" \
                      <my_containers_network> 

A sample command will resemble the following:

docker network create --driver bridge \
                      --gateway 172.25.0.1 \
                      --subnet 172.25.0.0/16 \
                      --opt "com.docker.network.bridge.name"="quotesdb-0" \
                      quotesdb-net 

You can confirm the network configuration using ifconfig on the host, or docker network ls as well as docker network inspect <network_name>.

Once the network is set up, the container for the MySQL database can be configured within it.

To set up a QuotesAPI_MySQL container inside the network, do the following:

docker run --name <container_name> \ 
           --detach \
           --env-file <Docker_environmental_var_file> \
           --volume <named_data_volume_for_database>:/var/lib/mysql \
           --network <my_containers_network> \
           --ip <ipv4_address_for_the_container> \
           --hostname <name_of_the_virtual_host> \
           cycprime/quotesapi_mysql

A sample command will resemble the following:

docker run --name quotesdb_container \
           --detach \
           --env-file ./env/runtime/default.env \
           --volume quotes_database:/var/lib/mysql \
           --network quotesdb-net \
           --ip 172.25.0.15 \
           --hostname mysqlh \
           cycprime/quotesapi_mysql

The file, env/runtime/default.env, contains environment variables in Docker recognizable format. These environment variables are required to set up the MySQL database.

The name specified in the --hostname option should agree with the database server name used in the QuotesAPI configuration file for the database. By default, this file is located in Config/dbsettings.json file. Its location and filename can be changed in the appsettings.json, under DBSettings.

To set up a QuotesAPI web api server, do the following:

docker run --name <container_name> \
           --detach \
           --volume <named_data_volume_for_logs>:/app/Logs \
           --volume <named_data_volume_for_quotes_data_input>:/app/Data \
           --publish <non_ssl_ipv4:port>:5000 \
           --publish <ssl_ipv4:port>:5001 \
           --network <my_containers_network> \
           --hostname <name_of_the_virtual_host> \
           --add-host <db_hostname:db_ipv4> \
           cycprime/quotesapi

A sample command will resemble the following:

docker run --name quotesapi_container \
           --detach \
           --volume quotesapi_logs_volume:/app/Logs \
           --volume data_input:/app/Data \
           --publish 127.0.0.1:5000:5000 \
           --network quotesdb-net \
           --hostname apih \
           --add-host mysqlh:172.25.0.15 \
           cycprime/quotesapi:latest 

The values supplied to the --add-host option should be in sync with the values specified in the creation of the container for the QuotesAPI_MySQL image. The hostname specified in the --add-host command in turns need to be in sync with the database configuration specified in the dbsettings.json, or equivalent, file in the QutoesAPI container.

To seed the database, do the following:

docker run --rm \
           --name <container_name> \
           --network <my_containers_network> \
           --volume <named_data_volume_for_logs>:/app/Logs \
           --volume <local_directory_for_quotes_data_file>:/app/Data \
           --add-host <db_hostname:db_ipv4> \
           cycprime/quotesapi --mode setup --seed /app/Data/<quote_data_filename>

A sample command will resemble the following:

docker run --rm \
           --name quotesapi_console \
           --network quotesdb-net \
           --volume quotesapi_logs_volume:/app/Logs \
           --volume /home/cyc/Development/GitHub/QuotesAPI/Data:/app/Data \
           --add-host mysqlh:172.25.0.15 \
           cycprime/quotesapi --mode setup  --seed /app/Data/Sheet1.json 

To view the quotes that you have input via the console, launch a web browser, type in the IP address and port as specified in the QuotesAPI docker run command. In the examples listed here, the URL would be http://127.0.0.1:5000.

If everything is set up properly, you should see the Swagger page, allowing you to try out the API interface.

To clean up the database table, do the following:

docker run --rm \
           --name <container_name> \
           --network <my_containers_network> \
           --volume <named_data_volume_for_logs>:/app/Logs \
            --add-host <db_hostname:db_ipv4> \
           cycprime/quotesapi --mode cleanup

A sample command will resemble the following:

docker run --rm \
           --name quotesapi_console \
           --network quotesdb-net \
           --volume quotesapi_logs_volume:/app/Logs \
           --add-host mysqlh:172.25.0.15  \
           cycprime/quotesapi --mode cleanup
Docker Pull Command
Owner
cycprime

Comments (0)