This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9956|Reply: 1

Docker creates an Nginx container

[Copy link]
Posted on 9/28/2018 1:04:48 PM | | | |
Operating environment: Centos 7
docker version: Docker version 1.13.1, build 6e3bb8e/1.13.1

1: Pull the nginx image



2: Run the nginx container



Understand the configuration file location of the Nginx image
Log file location: /var/log/nginx
Configuration file location: /etc/nginx
The location of the resource is /usr/share/nginx/html


Finally, run the nginx command inside the container to start

Access: http://ip to access our nginx container, as shown in the figure below:



3: Configurable nginx container

The configurable here does not mean that it cannot be configured in the nginx container, we configure it on the host machine, and then let the container read the file of the host machine to run, so that we don't have to go to the container to modify the configuration every time.

First, we create 3 files under the home folder



docker_nginx/log log folder
docker_nginx/conf nginx configuration folder
docker_nginx/html resource storage folder



Copy the configuration file for nginx in our docker

The above command will copy the entire directory with nginx,Use the following command to copy only the configuration file








Close our container and delete




Mapping the Nginx image to our native directory makes it easier for us to modify the file



Running here, we may still find that access to http://ip/ is inaccessible. Continue to check the information online, refer to the following:

When I ran it before, it was generally interactive:

-i ensures that the container's stdin is enabled -t to generate a tty terminal for the container, and a /bin/bash is added at the end of the command to ensure interaction. But in reality, nginx is not running, leading me to think that the container's port binding is not persistent.

Next we need to turn it off and delete our containerand restart one with the following command:





We can't get the content when we revisit http://ip because we don't have any files under the /home/docker_nginx/html/ directory of our host.

Let's create a new index.html file under the host's /home/docker_nginx/html/ directory and enter any content, as shown in the figure below:





Refresh the http://ip URL, and you can access it normally, as shown in the figure below:


Go to the nginx container


Or execute commands



What does bin/bash mean after it?
This means that after loading the container, bash must be run in docker, otherwise the entire container will exit.
This means starting bash after starting the container


End





Previous:Oracle views the structure of the table through SQL
Next:Programmer jokes and pictures
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com