Docker

Table of contents

  1. Run
  2. Configuration
  3. Loggers
  4. Examples

cli docker

Run

➜ docker run -d \
    -p 3000:80 \
    ealen/echo-server:0.9.2

➜ curl -I localhost:3000
HTTP/1.1 200 OK

Configuration

You can use environment variables with -e ENV_NAME=VALUE or CLI arguments after image’s name ealen/echo-server:0.9.2 --arg value More information

  • With environment variables:
➜ docker run -d \
    -p 3000:80 \
    -e ENABLE__ENVIRONMENT=false
    ealen/echo-server:0.9.2
  • With CLI arguments:
➜ docker run -d \
    -p 3000:80 \
    ealen/echo-server:0.9.2 --enable:environment false

Loggers

More information

➜ docker run -d \
    -p 3000:80 \
    -e LOGS__SEQ__ENABLED=true \
    -e LOGS__SEQ__SERVER=http://localhost:5341 \
    ealen/echo-server:0.9.2

➜ docker run -d \
    -p 3010:3010 \
    -p 5341:5341 \
    -e ACCEPT_EULA=Y \
    datalust/seq:0.9.2

Examples

Custom responses

Query Header Content Conditions
?echo_code= X-ECHO-CODE HTTP code 200, 404 200 <= CODE <= 599
    404-401 or 200-500-301  
?echo_body= X-ECHO-BODY Body message  
?echo_env_body= X-ECHO-ENV-BODY The key of environment variable Enable environment true
?echo_header= X-ECHO-HEADER Response Header Lang: en-US Enable header true
?echo_time= X-ECHO-TIME Wait time in ms 0 <= TIME <= 60.000
?echo_file= X-ECHO-FILE Path of Directory or File Enable file true

You can change commands and conditions.

Custom HTTP Status Code

➜ curl -I --header 'X-ECHO-CODE: 404' localhost:3000
➜ curl -I localhost:3000/?echo_code=404

HTTP/1.1 404 Not Found
➜ curl -I --header 'X-ECHO-CODE: 404-300' localhost:3000
➜ curl -I localhost:3000/?echo_code=404-300

HTTP/1.1 404 Not Found
HTTP/1.1 300 Multiple Choices
for i in {1..10}do
➜    curl -I localhost:3000/?echo_code=200-400-500
➜ done

HTTP/1.1 500 Internal Server Error
HTTP/1.1 400 Bad Request
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error
HTTP/1.1 200 OK
HTTP/1.1 500 Internal Server Error

Custom Body

➜ curl --header 'X-ECHO-BODY: amazing' localhost:3000
➜ curl localhost:3000/?echo_body=amazing

"amazing"

Custom Body with environment variable value

➜ curl --header 'X-ECHO-ENV-BODY: HOSTNAME' localhost:3000
➜ curl localhost:3000/?echo_env_body=HOSTNAME

"c53a9ed79fa2"
for i in {1..10}do
➜    curl localhost:3000/?echo_env_body=HOSTNAME
➜ done

"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"
"f10c3af61e40"
"c53a9ed79fa2"

Custom Headers

➜ curl --header 'X-ECHO-HEADER: One:1' localhost:3000
➜ curl localhost:3000/?echo_header=One:1

HTTP/1.1 200 OK
One: 1
➜ curl --header 'X-ECHO-HEADER: One:1, Two:2' localhost:3000
➜ curl "localhost:3000/?echo_header=One:1,%20Two:2"

HTTP/1.1 200 OK
One: 1
Two: 2

Custom response latency

➜ curl --header 'X-ECHO-TIME: 5000' localhost:3000
➜ curl "localhost:3000/?echo_time=5000"

⏳... 5000 ms

You can change default validations with

ENVIRONMENT CLI Default
CONTROLS__TIMES__MIN –controls:times:min 0
CONTROLS__TIMES__MAX –controls:times:max 60000

(Latency is defined in milliseconds)

File/Folder explorer

➜ curl --header 'X-ECHO-FILE: /' localhost:3000
➜ curl "localhost:3000/?echo_file=/"

["app", "bin", "etc", "usr", "var"]

Combine custom actions

➜ curl --header 'X-ECHO-CODE: 401' --header 'X-ECHO-BODY: Oups' localhost:3000
➜ curl "localhost:3000/?echo_body=Oups&echo_code=401"

HTTP/1.1 401 Unauthorized
"Oups"