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.
Create the Composer define file
Create the docker-compose.yml file and write code below.
version: "3" services: nginx: build: . ports: - 8080:80 volumes: - ./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.
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.
NginxはPOSTで接続するとHTTP 405のエラーになり、「405 Not Allowed」というメッセージ…
- 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.