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.

Author Profile

Akira HayashiA professional developer specializing in macOS Apps, iOS Apps, SDKs and middleware development.
Representative of RK Kaihatsu. I am a professional developer specializing in macOS Apps, iOS Apps, SDKs and middleware development. I often use ObjC, Swift and C++. Based on development experience, I provide e-learning contents, technical books and technical guidance. I am also a technical seminar instructor, in-house training instructor, and administrative / local goverment staff training instructor.
Get the Latest News !
>Programming Tips From Software Engineer

Programming Tips From Software Engineer

Technical News, Documents and Tips.