docker container virtualization technology

In simple terms, the installation of various operating environment under Windows systems do not just pit too much (● ¯ (Ester) ¯ ●), and is not limited to docker, Nginx, PHP, Python, etc. , I will try out the details of the actual wonderful variety of problems encountered in the process

1.docker For the environment

In fact, docker itself does not have much in Windows a lot of effort. Currently, docker only supports Linux and Windows Enterprise Edition, Professional Edition, Education Edition. ps: Home Edition does not support Docker , and can be installed under win10 Docker-for-Windows , this installation package is
specially adapted for win10, simple installation, and for win7 / 8 you can use the Docker Toolbox Download

Can not access port (port mapping problem) for docker container under 2.Windows

1. Issue Details

   installed and docker docker-compose in Windows10 system server

   and try to run Nginx in which the service is also good mapping

   problem: the host browser, open localhost: port can not access the corresponding Web service.

2. Problem Analysis

   reason: docker is running on Linux, running on Windows docker, in fact or in Windows to install a Linux environment, then docker run in this system. In other words, the service used localhost refers to the address of the Linux environment, rather than our hosting environment Windows10.

3. Solution

   start docker command line window

   enter the command: docker-Machine ip default

   Linux ip address, under normal circumstances this address is 192.168.99.100

   and then in the Windows browser, type http: // IP: port to enable (http://192.168.99.100:8069)

3.docker not compatible with VMware

   Docker installed in Windows, the first step is to open the Hyper-V (Open the Control Panel - Programs and Features - Enable or disable Windows features, check the Hyper-V), open the win comes with a virtual management techniques. However, if you want to use VMware, you must turn off Hyper-V, you can not have both fish and bear's paw! ( 'Д `) ... ... San San

4.Windows:vmware incompatible with hyper-v, remove the hyper-v role

1, remove the hyper-v role.
(1) an administrator (win + x) run the command prompt;
(2) Run: the bcdedit / OFF SET hypervisorlaunchtype
(. 3) to restart the system, you can run vm.
2, if you want to restore hyper start:
   bcdedit / hypervisorlaunchtype the SET Auto

5.docker then after run / bin / sh and pick what / bin / bash difference:

For example, we want to get a nginx mirror, the same mirror there different tags
   / bin / SH command applies only to tags with alpine label: nginx: 1.17-alpine;
   / bin / bash command applies only to tags without alpine identified: nginx: laster, nginx: 1.8 ...

6. Docker running MySQL service

  1. Pulling mirror
    docker pull mysql: [tag]
  2. Create and run a container
    docker run --name mysql -p 3306: 3306 -e MYSQL_ROOT_PASSWORD = 123456 -d mysql: 5.6

ps: -p indicates that the specified access port
      -e set environment variables, or overwrite the existing environment variables
      -d represented by formula guardian way to run container
       MYSQL_ROOT_PASSWORD = 123456 declare MySQL user name ROOT, the password is 123456

  1. Check whether the container start
    docker ps
  2. Start container
    docker start container_id
  1. Into the interior of the container to the command line interaction
    docker exec -it container_id / bin / bash
  1. Log in MySQL
    MySQL -u root -p and then enter the password
  1. It said it had successfully landed successfully MySQL

7. The most universal formula: Volume data creating container mount of formula

 守护式:docker run -di [--privileged=true] -P(或者指定端口 -p 外部port:该容器默认端口) \--name="newNginx"  -v /home/chd/Desktop/entwechatapp:/var/www/EntWeChatApp:rw  nginx:1.15.7-alpine
 交互式:docker run -it [--privileged=true] -P(或者指定端口 -p 外部port:该容器默认端口) \--name="newNginx"  -v /home/chd/Desktop/entwechatapp:/var/www/EntWeChatApp:rw  nginx:1.15.7-alpine
 含义:
    a) 以-v /home/chd/Desktop/entwechatapp:/var/www/EntWeChatApp:rw 带rw(read,write)权限来将宿主机与容器进行数据卷挂载
    b) docker run 以新容器名和端口号以及守护式或者交互式来创建容器

8. The host and the docker container permissions disputes

Problem Description:
      It has come! The problem has emerged! Weep too. When data volumes to mount, even if declared rw permissions to create files in the host machine, after data sharing, the container can have a normal rw privilege; but after a new file in the container, the host will have read-only privileges to modify the contents of the file.

Solution: host of the lack of privilege
      in (7) where the universal formula added: docker run ··· --privileged = true ···

9. Docker nginx configuration profiles

Command: docker run --name="dnmp_nginx" -p 80:80 -v /home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/docker-nginx/log:/var/log/nginx -v /home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -di nginx:\[tags]
    The first -v said it will cover your local nginx.conf nginx.conf file you want to start from the container, and the second said it would mount a log file is written to the log server nginx places you docker host / home / docker-nginx / log / below. The third and means the same as the first -v -v represented
    Personally, I prefer the guardian of mapping the way, the trouble is the need to be ready nginx.conf and default.conf documents myself, I was copied directly from the container inside then change according to their needs

I want to kill it, too nginx deployment pit, but reference this blog , finally solved the problem, the solution:

1. Create three root directory under the circumstances created: / docker / nginx / conf www logs

docker run -d -p 80:80 --name="nginx" --net host -v /docker/nginx/www:/usr/share/nginx/html -v /docker/nginx/logs:/var/log/nginx nginx:1.17.5

2. The right to mount the profile data that is

The -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf

3. get into the container file

docker exec -it nginx /bin/bash

4.cd /etc/nginx/

(This is mainly to get the configuration file path), then exit

5. Data Copy

Host file into the directory cd / docker / nginx / conf /
the container has run successfully copy the configuration file to the configuration file directory of the host: docker cp container ID: /etc/nginx/nginx.conf (ps:. " . "represents a copy of the current directory)

ps: After the file copy the success of the first container nginx deleted

6. Create the ultimate nginx container

docker run -di -p 80:80 
--name nginx 
[--net host] :再思考一下有没有必要写,使用–net = host时,它告诉容器使用主机网络堆栈.因此无法将端口暴露给主机,因为它是主机(就网络堆栈而言).
-v /docker/nginx/www:/usr/share/nginx/html 
-v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /docker/nginx/logs:/var/log/nginx 
nginx:1.17.5
ps:成功后就代表部署成功

2019-11-29 New:
      Here nginx.conf host is actually mount a file, docker is not recommended for such use, you can try to create a directory on the host is: / docker / nginx / conf / nginx. conf / nginx.conf (current conf file is a specific configuration file, not a directory), so the formula will not appear warning Docker
, in conjunction with this article .

PS: access may be because 403 / docker / nginx / www / index.html which did not go into enough

7. privileges granted

After a successful mount, to www directory (or entire file directories) increased privileges on the host, or have been unable to read and write:
    sudo chmod -R 777 directory goals: to impart maximum target directory administrator privileges
    sudo chmod +/- rwx file name | directory to the file or directory to give permission

10.docker configure MySQL, redis tutorials, please click this link

command:docker run -di -p 12345:3306 \--name="mysql" -v /lnmp/mysql/conf:/etc/mysql/conf.d -v /lnmp/mysql/logs:/logs -v /lnmp/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456:rw mysql:5.6

Command Description:
-p 12345: 3306: 12345 maps the host port 3306 to port docker container.
--name mysql: run the service name
-v /lnmp/mysql/conf:/etc/mysql/conf.d: the conf / my.cnf under the host / lnmp / mysql record container mounted to the / etc / mysql / the conf.d
-v / lnmp / mysql / logs: / logs: the host logs directory / lnmp / mysql directory is mounted to the container / logs.
-v / lnmp / mysql / data: / var / lib / mysql: a data directory of the host / lnmp / mysql directory is mounted to the container / var / lib / MySQL
-e MYSQL_ROOT_PASSWORD = 123456: initializing the root password.
-d mysql: 5.6: daemon running mysql5.6

How Windows 11. External access to the container in the docker

1. Basic architecture: Windows, Dockers, Linux three relations
Windows, Dockers, Linux three relations

2. related operations

2.1 closed Linux firewall: systemctl stop firewalld.service

2.2 View Linux, Docker's IP address: ifconfig (different from the Windows ipconfig command)

2.3 Windows access the test:

Thought: docker container as a virtual technology to create and start the associated container services, and the port is mapped to the Linux system. For example, MySQL: MySQL service start after docker, and mapped an external access to the ports (for example, or 3306)
, is now Linux on a port that has a 3306 => outside access method should be: with the access to virtual machines with Linux binding docker container port mapped out.


2019-11-27 New:
access to the linux nginx in the windows system, default can not be accessed because of firewall issues that we can have two solutions
(1) turn off the firewall: reference to the above related operations
(2) open access port number, such as port 80, as follows:

View open port number

firewall-cmd --list-all

Set open port number

--add-cmd-Service-Firewall = HTTP --permanent
Firewall --add-Port-cmd = 80 (or other open port number) / tcp --permanent

Restart the firewall

firewall-cmd --reload

Guess you like

Origin www.cnblogs.com/AhriLove-chen/p/12059066.html