Class: Testcontainers::NginxContainer

Inherits:
DockerContainer
  • Object
show all
Defined in:
lib/testcontainers/nginx.rb

Overview

NginxContainer class is used to manage containers that run an NGINX server

Constant Summary collapse

NGINX_DEFAULT_PORT =

Default port used by the container

80
NGINX_DEFAULT_IMAGE =

Default image used by the container

"nginx:latest"

Instance Method Summary collapse

Constructor Details

#initialize(image = NGINX_DEFAULT_IMAGE, port: nil, **kwargs) ⇒ NginxContainer

Initializes a new instance of NginxContainer

Parameters:

  • image (String) (defaults to: NGINX_DEFAULT_IMAGE)

    the image to use

  • port (String) (defaults to: nil)

    the port to use

  • kwargs (Hash)

    the options to pass to the container. See DockerContainer#initialize



19
20
21
22
# File 'lib/testcontainers/nginx.rb', line 19

def initialize(image = NGINX_DEFAULT_IMAGE, port: nil, **kwargs)
  super(image, **kwargs)
  @wait_for ||= add_wait_for(:logs, /start worker process/)
end

Instance Method Details

#portInteger

Returns the port used by the container

Returns:

  • (Integer)

    the port used by the container



35
36
37
# File 'lib/testcontainers/nginx.rb', line 35

def port
  NGINX_DEFAULT_PORT
end

#server_url(protocol: "http") ⇒ String

Returns the server url (e.g. host:port)

Parameters:

  • protocol (String) (defaults to: "http")

    the protocol to use in the string (default: “http”)

Returns:

  • (String)

    the server url

Raises:

  • (ConnectionError)

    If the connection to the Docker daemon fails.

  • (ContainerNotStartedError)

    If the container has not been started.



45
46
47
# File 'lib/testcontainers/nginx.rb', line 45

def server_url(protocol: "http")
  "#{protocol}://#{host}:#{mapped_port(port)}"
end

#startNginxContainer

Starts the container

Returns:



27
28
29
30
# File 'lib/testcontainers/nginx.rb', line 27

def start
  with_exposed_ports(port)
  super
end