Похоже, что Из документации докера отвечает на ваш вопрос довольно исчерпывающе:
По умолчанию все внешние IP-адреса разрешено подключаться к демону Docker. Чтобы разрешить доступ к контейнерам только для определенного IP-адреса или сети, вставьте отрицательное правило вверху цепочки фильтров DOCKER. Например, следующее правило ограничивает внешний доступ ко всем IP-адресам, кроме 192.168.1.1:
blockquote>$ iptables -I DOCKER-USER -i ext_if ! -s 192.168.1.1 -j DROP
Чтобы разрешить определенную подсеть:
iptables -I DOCKER-USER -i ext_if ! -s 192.168.1.0/24 -j DROP
Бонус: вы также можете полностью ограничить соединения с localhost:
docker run -p 127.0.0.1:80:8003
должен автоматически ограничить доступ к localhost.В качестве альтернативы с докером составляют:
webapp: image: image_name ports: - "127.0.0.1:80:8003"
Нет, нет. Необходимо будет сделать форматирование себя или найти стороннюю библиотеку, которая сделает это самих.
Вы могли использовать DataTableReader:
public static string PrintTable(this DataTable dt)
{
DataTableReader dtReader = dt.CreateDataReader();
StringBuilder result = new StringBuilder();
while (dtReader.Read())
{
for (int i = 0; i < dtReader.FieldCount; i++)
{
result.AppendFormat("{0} = {1}",
dtReader.GetName(i).Trim(),
dtReader.GetValue(i).ToString().Trim());
}
result.AppendLine();
}
dtReader.Close();
return result.ToString();
}
Рекомендую ознакомиться с моей статьей DataTable Formatter
Мой класс DataTableFormatter содержит методы для форматирования таблиц DataTable в виде символьных таблиц (ваше требование), таблиц HTML или таблиц документа потока.
Вы можете скачать проект, содержащий класс, с моего сайта, но для удобства я размещу код здесь.
/// <summary>
/// Gets a string representation of the <see cref="System.Data.DataTable" />.
/// </summary>
/// <remarks>The string representation should be displayed with a monospaced font.</remarks>
public static string GetStringRepresentation(DataTable dataTable)
{
if (dataTable == null)
throw new ArgumentNullException("'dataTable' cannot be null.");
StringWriter representationWriter = new StringWriter();
// First, set the width of every column to the length of its largest element.
int[] columnWidths = new int[dataTable.Columns.Count];
for (int columnIndex = 0; columnIndex < dataTable.Columns.Count; columnIndex++)
{
int headerWidth = dataTable.Columns[columnIndex].ColumnName.Length;
int longestElementWidth = dataTable.AsEnumerable()
.Select((row) => row[columnIndex].ToString().Length)
.Max();
columnWidths[columnIndex] = Math.Max(headerWidth, longestElementWidth);
}
// Next, write the table
// Write a horizontal line.
representationWriter.Write("+-");
for (int columnIndex = 0; columnIndex < dataTable.Columns.Count; columnIndex++)
{
for (int i = 0; i < columnWidths[columnIndex]; i++)
representationWriter.Write("-");
representationWriter.Write("-+");
if (columnIndex != dataTable.Columns.Count - 1)
representationWriter.Write("-");
}
representationWriter.WriteLine(" ");
// Print the headers
representationWriter.Write("| ");
for (int columnIndex = 0; columnIndex < dataTable.Columns.Count; columnIndex++)
{
string header = dataTable.Columns[columnIndex].ColumnName;
representationWriter.Write(header);
for (int blanks = columnWidths[columnIndex] - header.Length; blanks > 0; blanks--)
representationWriter.Write(" ");
representationWriter.Write(" | ");
}
representationWriter.WriteLine();
// Print another horizontal line.
representationWriter.Write("+-");
for (int columnIndex = 0; columnIndex < dataTable.Columns.Count; columnIndex++)
{
for (int i = 0; i < columnWidths[columnIndex]; i++)
representationWriter.Write("-");
representationWriter.Write("-+");
if (columnIndex != dataTable.Columns.Count - 1)
representationWriter.Write("-");
}
representationWriter.WriteLine(" ");
// Print the contents of the table.
for (int row = 0; row < dataTable.Rows.Count; row++)
{
representationWriter.Write("| ");
for (int column = 0; column < dataTable.Columns.Count; column++)
{
representationWriter.Write(dataTable.Rows[row][column]);
for (int blanks = columnWidths[column] - dataTable.Rows[row][column].ToString().Length;
blanks > 0; blanks--)
representationWriter.Write(" ");
representationWriter.Write(" | ");
}
representationWriter.WriteLine();
}
// Print a final horizontal line.
representationWriter.Write("+-");
for (int column = 0; column < dataTable.Columns.Count; column++)
{
for (int i = 0; i < columnWidths[column]; i++)
representationWriter.Write("-");
representationWriter.Write("-+");
if (column != dataTable.Columns.Count - 1)
representationWriter.Write("-");
}
representationWriter.WriteLine(" ");
return representationWriter.ToString();
}
Метод GetStringRepresentation(DataTable) дает результаты вроде этого
+------------------+----------------+-------------------+ | Item | Units in Stock | Unit Price | +------------------+----------------+-------------------+ | Drilling machine | 1000 | $1,000,000 | | Backpack | 320 | $24 | | Chocolate bar | 100000 | $2.00000000000000 | +------------------+----------------+-------------------+
Должен признать, что этот стиль таблицы списан с клиента командной строки MySQL.