How to set Docker nginx

How to set nginx with Docker

Since we introduced nginx using Docker, the contents are summarized below.

-Obtain a Docker image from the Docker hub.

Docker hub URL https://hub.docker.com/_/nginx

Copy the contents of the black box on the upper right of the link destination image.png

% docker pull nginx 

The nginx image is installed.

↓ Confirmation

% docker images
nginx               latest              f35646e83998        3 weeks ago         133MB
・ Enter the container
% docker run -it -p 8080:80 nginx bin/bash

-it can fit inside a container It seems that it is local 8080 that accesses port 80 of the virtual environment.

・ Command to enable vim
% apt update && apt install -y vim
-Command that allows you to check the settings of the vim file
% vi /etc/nginx/nginx.conf 

Return with: q!

-Command that enables the ps command
apt update && apt install -y procps
Command to see the items for each running process
% ps aux

Access localhost: 8080 port → Start

If it is displayed like this, nginx has started successfully. image.png

・ Stop the process
% nginx -s stop  
・ Exit from the container, stop

Control + D

・ Commit the environment where vim and ps can be used
docker commit container ID new name create new docker
% docker images                               
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              f35646e83998        3 weeks ago         133MB
docker commit 4fe63b604f41 nginx-new

A new image of nginx-new is created.

% docker images                               
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              f35646e83998        3 weeks ago         133MB
nginx-new           latest              9b8e8bcd32fe        33 minutes ago      185MB
  • See above for how to start with nginx-new after that

Recommended Posts