Learn to use docker on CentOS7 [Install Nginx]

Download mirror

docker pull nginx

start the container

docker run -d -p 8080:80 nginx

Map port 80 of nginx in the container to port 8080 of the current server, enter http://192.168.1.120:8080/ in the browser , and you can see that nginx has been started. Enter image description

remove the nginx container

  1. First look at the running container
[root@izbp1e0h5tks006vnlaro4z bin]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
94db415a384f        nginx               "nginx -g 'daemon ..."   About an hour ago   Exited (0) 18 minutes ago                       affectionate_kowalevski
b136815d5dfc        nginx               "nginx -g 'daemon ..."   About an hour ago   Created                                         sad_heisenberg

  1. stop container
[root@izbp1e0h5tks006vnlaro4z bin]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                  NAMES
4e882347dfec        nginx               "nginx -g 'daemon ..."   About a minute ago   Up About a minute   0.0.0.0:8081->80/tcp   ecstatic_noyce
[root@izbp1e0h5tks006vnlaro4z bin]# docker stop 4e882347dfec
4e882347dfec

  1. delete container
[root@izbp1e0h5tks006vnlaro4z bin]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
94db415a384f        nginx               "nginx -g 'daemon ..."   About an hour ago   Exited (0) 23 minutes ago                       affectionate_kowalevski
b136815d5dfc        nginx               "nginx -g 'daemon ..."   About an hour ago   Created                                         sad_heisenberg
[root@izbp1e0h5tks006vnlaro4z bin]# docker rm b136815d5dfc
b136815d5dfc
[root@izbp1e0h5tks006vnlaro4z bin]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
94db415a384f        nginx               "nginx -g 'daemon ..."   About an hour ago   Exited (0) 23 minutes ago                       affectionate_kowalevski
[root@izbp1e0h5tks006vnlaro4z bin]# docker rm 94db415a384f
94db415a384f
[root@izbp1e0h5tks006vnlaro4z bin]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Specify the parameters of the container nginx

docker run --name nginx-001 -d -p 8080:80 -v /home/docker/nginx/html:/usr/share/nginx/html nginx

The -p parameter is to map the host's port 8080 to the container's port 80. Note that -v is a data volume, and the directory /home/docker/nginx/html can be shared between the host and the container. In the container, it is /usr/share /nginx/html. In fact, this is our code directory. The debugging code is realized by the shared directory, which is very convenient! !

Modify the configuration file in the container

#进入容器
$docker exec -it nginx-001 bash
#安装工具
apt-get update
apt-get install vim
#查看和修改nginx的配置信息
vim /etc/nginx/conf.d/default.conf

Reference blog post address: please poke me, poke hard

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324933845&siteId=291194637