[Docker] practice - deployed static websites in a container

  • Creating interactive map port 80 containers
  • Install Nginx
  • Install the text editor vim
  • Creating a static page
  • Modify the configuration file Nginx
  • Running Nginx
  • Verify web access

1, interact with the container to be run a port mapping, named web

docker run -p 80 --name web -i -t ubuntu /bin/bash

2, into the container, the installation Nginx

apt-get install -y nginx

3, (optional) for the operating results found unable to locate package nginx, you need to perform the following command

apt-get update

 After machining, go to execute the command installation of nginx

4, to continue the installation of vim apt-get

apt-get install -y vim

After installation, we started to create a Web site to run in the nginx

5, create a directory of a storage site

mkdir -p / var / www / html

6, into the newly-built directory

cd / var / www / html

7, using vim create and edit a static page

vim index.html

8, create a simple static page

<html>
 <head>
  <title>nginx</title>
 </head>
 <body>
  <h1>Hello World</h1>
 </body>
</html>

Then we started to edit the configuration file nginx

9. Find nginx installation location

whereis nginx

10, look for nginx configuration file location

ls /etc/nginx
ls /etc/nginx/sites-enabled

11, open the default file

vim /etc/nginx/sites-enabled/default

12, the value of the root file location is changed to the newly established website

root / var / www / html;

13, switching to the root directory

cd /

14, running nginx

nginx

15, ps view the current progress in the container, whether running nginx

ps -if

16, Exit container

ctrl+Q/P

17, see the map container port

docker ps
或
docker port web

18, curl to see whether the site can be accessed (host ip address)

curl http://127.0.0.1: Mapping port

19, curl to see whether the site can be accessed (container ip address)

# Ip} {get $ 
Docker the Inspect --format = 'range.NetworkSettings.Networks {{}} {{IPAddress}.} {{End}}' Web
# to access the page
curl http: // $ {ip}

20, we try to stop the container

sudo docker stop web

21, restart the container

sudo docker restart web

22, see the map again container port, the port changes found

 

Guess you like

Origin www.cnblogs.com/CSgarcia/p/11350912.html
Recommended