A DockerFile.

Dockerfile is a text file containing instructions, each Instruction builds a layer, so the content of each Instruction describes how the layer should be built.

As a simple customization example, we create a file called DockerFile and write it as follows

FROM nginx RUN echo '<h1>Hello, Docker! </h1>' > /usr/share/nginx/html/index.htmlCopy the code

This completes the customization of an Nginx image, so we start the customized image, and nginx services that access the image should get Hello, Docker! The output.


Use DockerFile to customize the image


Docker network

Docker network is a very important concept. If we study Docker deeply, we will find that future CI/CD, cluster deployment and other operations are inseparable from the network communication between Docker. Therefore, it is very important to learn the network foundation and principle of Docker well.


When Docker is started, it automatically creates a Docker0 virtual bridge on the host, which is actually a Linux bridge and can be understood as a software switch. It forwards between ports mounted to it.

At the same time, Docker randomly assigns an address in a private network segment (defined in RFC1918) that is not used locally to the docker0 interface. For example, a typical 172.17.42.1 is 255.255.0.0. The network ports in the container that are started later are automatically assigned an address on the same network segment (172.17.0.0/16).


Docker network principle and Docker advanced network configuration

1. Basics: Access the Docker container externally

  • When using the Docker run command, you can use two parameters to bind the host port to the docker open port, namely -p and -p.

  • When the -p flag is used, Docker will randomly map a port from 49,000 to 49900 to the open network port of the internal container.

  • When -p is used, you can specify the port to be mapped, and only one container can be bound to a specified port.

  • When binding, you can specify either IP address or port. If the host port is not specified, Docker will randomly assign it.

[root@undi]# docker run -p 8080:80 nginx          
#Bind port 8080 of the host to port 80 of the container, so that access to port 8080 of the host will be forwarded to port 80 of the container
Copy the code
[root@undi]#Docker run -p 127.0.0.1::80 nginx
#Bind a random host port 127.0.0.1 to port 80 of the container
Copy the code


2. View the ports bound to the container

  1. usedocker ps -aLists all containers, where you can see the ports to which containers are bound.
  2. useDocker Post container nameYou can view the IP bound to the container.
  3. useDocker inspect specifies the container nameYou can see all the variables.
[root@undi]# docker port bloomfilter6379 / TCP - > 0.0.0.0:6379Copy the code


3. Interconnect containers

The first way is to use – the link parameters, but is not recommended to use this way to connect, now he works in a container of host file to add mapping relationship, not only poor portability, in turn, also not line, wall cracks recommend to add custom network links more containers, as we have to play virtual machine when the virtual network adapter.


New network

Create a new Docker network

$ docker network create -d bridge my-net
Copy the code

The -d parameter specifies the Docker network type, including Bridge overlay. The overlay network type is used for Swarm mode and can be ignored here.


Connect the container

Run a container and connect to your new My-Net network

$ docker run -it --rm --name busybox1 --network my-net busybox sh
Copy the code


Open a new terminal, run another container and join the my-NET network

$ docker run -it --rm --name busybox2 --network my-net busybox sh
Copy the code


We have two containers busyBox1 and busyBox2. We can ping one of them successfully and vice versa

# ping busybox2PING busybox2 (172.19.0.3): 56 data bytes 64 bytes from 172.19.0.3: Seq =0 TTL =64 time=0.072 ms 64 bytes from 172.19.0.3: seq=1 TTL =64 time=0.118 msCopy the code


Iii. Intellij Idea integration with Docker

Crazy teacher free video, 2020-05-16 13:37:32 released video, or quite new

Because the video is recorded and broadcast, there is no clip, so crazy brother hit the wrong word or tangled time a little more, suggest times as fast, dry goods are some.