The Docker is useful to test and to debug the code to connect with HTTP/HTTPS

If you implement the code to communicate with HTTP or HTTPS, you may want to test it with fixed response.

The docker is useful to do it. It can create and run the container which contains the Nginx, the web server. You can test your application with this container.

How to create the container

Create the docker image

To create the docker image, create the file with name ‘Dockerfile’ and write below.

FROM nginx:1.17

Create the Composer define file

Create the docker-compose.yml file and write code below.

version: "3"
    build: .
      - 8080:80
      - ./content_home:/usr/share/nginx/html

Create public files

Create the folder with name ‘content_home’ into the same directory of docker-compose.yml and Dockerfile. The ‘content_home’  is a root folder of the web site, you put the public files into this folder.

Run the container

Execute following line in the directory has docker-compose.yml file.

$ docker-compose up -d

Open with the web browser

The web server URL is below.


Stop the container

Execute following command to stop.

docker-compose stop


You can easily create the web server with the Docker.

Define files can be managed with Git. It make the infrastructure can be written with the code and managed with Git.

However, if your application connect to this container with HTTP POST Method, the container will returns the HTTP Status 405 Error.

I also wrote the post that explains how to support the HTTP POST method with Nginx container.

How to configure the Nginx to support the HTTP POST method

Sponsored Links
Get the Latest News !

Developer ToolsLatest 8 Posts