docker self built warehouse and network

docker network creation

Containers themselves cannot be networked with each other, but they can be interconnected by placing them in the same network segment.
Can pass

docker network create creates a network segment name

To create network segments, we can also use docker network ls to view network segments. By default, there will be three network segments when docker does not create network segments. These three built-in network segments cannot be interconnected. Therefore, if we want to build a new architecture, such as lamp and LNMP, we need to create a network, When the containers are started, these containers are placed on the created network, so as to realize container interworking.
We can create one manually, such as docker network create lamp. Then we can check the network card at this time.

You can see that a new network segment will appear in the network card segment, and it will be named at the beginning of docker. In the future, when creating a new network, their network segments are different, so as to realize the interworking between the same network and the isolation between different networks.

docker network allocation command

When we open an image, we can use

docker run -itd -p port number -- name -- network the assigned network depends on the image bash to run

Or you can enter the name of the network container assigned by docker connect in the running container to allocate the network

Self built image warehouse

There are three ways to obtain the image. One is to create the image by writing a script. The other is to pull the image through the docker hub official website. The data image of the official website is relatively complete. However, due to its own foreign website, the access time will be broken, pull failure, packet loss and other phenomena. The third is the practice of many domestic enterprises, that is, build a container warehouse, and then pull the self built images one by one, which can be downloaded by servers in the same network segment.
Here is a command:

docker run -itd -p port number - v where to mount: where to mount to the container image name

The advantages of this command are similar to nfs, but it is shared between the local machine and the container. The corresponding directory will be generated at the specified place. Any file or application will be placed in the local machine, and the mount point of the container on the other side can receive it


1)The first thing you need is to download registry It is a warehouse source. We can start it directly through the following command, and the system will automatically docker hub Download the image package.

docker run -itd -p 5000:5000 registry

2)After downloading, you can docker ps Check whether the image is started. If not, enter a

> docker run -itd -p 5000:5000 registry

For manual opening.

3)After opening, you need to write a file manually to make ip Address sharing

vim /etc/docker/daemon.json
"insecure-registries": ["Local address:registry "Specified port number"]
"insecure-registries": [""]

4) Restart the docker container and restart the registry image

systemctl restart docker
 Because it needs to be permanently persistent, it needs to be mounted
docker run -d -p 5000:5000 -v /root/data:/var/lib/registry/docker/registry/v2

5) After a series of operations, you can upload the image!
1. The image needs to be renamed in the form of ip address: port number / image name: label

Example: docker push

3. After uploading, use curl to see if the upload is complete
4. You can also use the browser to enter the above web address for viewing


Build compose



> curl -L "$(uname
> -s)-$(uname -m)" -o /usr/local/bin/docker-compose

This is a download command. You need to install it first


> chmod +x /usr/local/bin/docker-compose

This is to increase the permissions of key configuration files


> ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

This is an additional soft connection

4)mkdir composetest 
5)cd composetest

import time
import redisfrom flask import Flask
app = Flask(__name__)cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
    retries = 5
    while True:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
@app.route('/')def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)

vim requirements.txt:


vim Dockerfile: 
FROM python:3.7-alpine
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["flask", "run"]

vim docker-compose.yml
version: "3.9"services:
    build: .
      - "5000:5000"
    image: "redis:alpine"

6) After creating a series of files, use the docker compose up - D command to complete the installation
7) Attention! Its default port is 5000. Please ensure that other port numbers do not conflict with 5000.
8) Then you can directly enter the local number: 5000 in the browser for access
9) Each refresh is counted

Command set

docker save -o export image
Docker load -- input < image import image
docker run -itd start / create
The network container name assigned by docker connect will reassign the assigned container to the network
Docker compose up - d start compose
docker search finds all keyword images of docker hub platform

Keywords: Operation & Maintenance Docker network

Added by cbn_noodles on Thu, 17 Feb 2022 22:56:45 +0200