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
|