This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging
Docker image container repository
Docker and virtualization
- Virtualization is a resource management technology. It abstracts and transforms various physical resources of computers, such as servers, networks, and memory, so that users can apply these resources in a better way.
The virtualization goal is to run multiple systems or applications on the same host to improve resource utilization, reduce costs, facilitate management, and facilitate disaster recovery (Dr).
- Operating system-level virtualization: The kernel isolates different processes by creating multiple virtual operating system instances (kernel and library). Docker and other container technologies fall into this category.
Container, warehouse, image running diagram:
1. Image
It is similar to a VM image
Search the mirror
docker search # Search for image in Docker index
--automated=false Displays only automatically created images. -- no-Trunc =false Displays the output information without truncation. -s 0 Indicates that only the images rated to the specified star are displayedCopy the code
Download mirror
docker pull Drop down image from Docker Registry Server
You can also download an image by specifying a label
docker pull [:TAG]
docker pull centos:7
Copy the code
View mirror/delete
Docker images: # lists images
Docker images -a # list all images (including history)
Docker ps -a # lists all containers on the machine
docker rmi : # Delete one or more images
Save and load images
Tar docker save -o ubuntu_14.04.tar Ubuntu :14.04 Importing an image to the local image library docker load --input ubuntu_14.04.tar or Docker load The < ubuntu_14. 04. TarCopy the code
Upload the image
After registering on dockerHub, users can upload their own images. docker push NAME[:TAG]Copy the code
2. Container
Run and isolate applications in a Linux-like environment.
When a container starts from an image, Docker creates a writable layer at the top of the image. The image itself is read-only and remains the same. A container is a running instance of an image, but with an extra writable layer.
The relationship between an Image and a Container is similar to that between classes and instances in object-oriented programming. The Image is a static definition and the Container is the entity that the Image runs on.
Containers can be created, started, stopped, deleted, or paused.
3. A Repository
Each repository stores a certain type of image.
A warehouse is a centralized place to store images. You can have multiple repositories on each server.
Warehouses are divided into public warehouses (DockerHub, Dockerpool) and private warehouses
DockerHub: docker officially maintains a public warehouse https://hub.docker.com, which includes more than 15,000 images, most of which can be downloaded directly through DockerHub.
It can also be downloaded using the docker search and docker pull commands.
DockerPool: domestic professional docker technology community, http://www.dockerpool.com also provides the official download mirror.
3.1 Construction of Docker private Warehouse:
192.168.2.189 warehouse
192.168.2.201 client
- 1. First pull the Registry image (for starting the repository) and the BusyBox image (for uploading)
docker pull registry
docker pull busybox
Copy the code
This is Registry 2
- 2. Use the docker tag command to mark the image as
192.168.2.189:5000 / busybox
Docker tag IMAGR[: tag] NAME[: tag] docker tag docker. IO /busybox 192.168.2.189:5000Copy the code
- 3. Modify the Docker configuration file and add parameters
- insecure - registry = 192.168.2.189:5000
The argument here specifies the non-secure mode, that is, HTTP instead of HTTPS, and the Docker service is restarted.
- 4. Create the Registry container and start it
docker run -d -p 5000:5000 --privileged=true -v /myregistry:/var/lib/registry registry
Copy the code
-
— privileged=true: Privileged container (OSError: [Errno 13] Permission denied: ‘/ TMP/registry/repositories/liibrary’) or (Received unexpected HTTP status: 500 Internal Server Error) Error
-
The -v option specifies that the /myregistry/ directory is mounted to /var/lib/registry. / TMP/Registry is the repository directory of Registry version 1.
-
/ MyRegistry creates a directory for the local.
-
5. Push the image of the local tag to the repository
Docker push 192.168.2.189:5000 / busyboxCopy the code
- 6. View the local directory/MyRegistry and pull the image just pushed on the client
The client also needs to modify the configuration file to specify the repository before pulling, add the parameter –insecure-registry=192.168.2.189:5000 as above, and restart Docker.
- 7. The Registry V2 API can also be used to check whether the push image exists in the repository
Install the software environment in Docker
Docker China official image acceleration www.docker-cn.com/registry-mi…
Docker China official image acceleration
In Linux, modify the /etc/docker/daemon.json file and fill in the following:
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
Copy the code
If daemon.json doesn’t exist, you need to create it yourself. After the file changes are saved, remember to restart the Docker service for the image to take effect quickly. Restart the Docker service We are in the centos system installation Docker 】 【 section about Docker as the content of the server restart automatically start, can through the command service Docker restart to realize the Docker service restart. For details, please visit yuque.com/zhoubang/do… Then we execute the command in Linux:
service docker restart
Copy the code
1. Docker pull XX (Recommended)
1.1 Obtaining a JAVA Image:
On the cli of the terminal client, run the following command to obtain the JAVA image.
docker pull java
Copy the code
By default, the image is downloaded from the official Docker Hub repository. If no version is specified, the image with latest version is obtained by default.
Note: Latest is the latest version of the software for the repository where the image resides. It’s not the latest release of the software itself.
2. View the downloaded image
Run the following command from the command line to view the JAVA image you just downloaded:
docker images
Copy the code
3. Start the container
Run the following command to start the JAVA image container:
docker run -d -it --name java java
Copy the code
-
The “Java” after the –name specifies an alias for the container, and the last “Java” refers to the name of the image downloaded.
-
Meanings of the command and parameters:
run
: Starts an image container-d
: Specifies that the container runs in the background-it
: abbreviation of -i and -t;-i
: Runs the container in interactive mode, usually in conjunction with -t-t
: reallocates a pseudo input terminal to the container, usually used in conjunction with -i--name
: Specifies the name of the container. You can manage the container by name
4. View the running containers
First we run a command on the command line to see which containers are running:
docker ps
Copy the code