Cloud native environment construction-Docker creates images and pushes and pulls Harbor

Create mirror 

2 ways

1. According to Dockerfile [build]

2. After modification based on the running container [commit]

Image and container association

1. Create a mirror based on the Dockerfile

1、mkdir dockerfile/lib/centos7base/

Create a directory

2. Create a Dockerfile

vim Dockerfile

 

Second, build a mirror

docker build -t python.

--tag, -t:  mirror name and tag

Process analysis
Let's take a look at the compilation process of docker

The first step of compilation will reuse the existing python. The
key point is that the second step
b48566f8cf2c is actually a temporary container id generated on the basis of the python image.
We ignore the installation process and skip to the end.

 

Finally, according to the temporarily generated container, docker commit generates the image file, and finally deletes the temporary container (compare with the diagram at the beginning of the blog)
 

Third, build an image based on the container

 1. Pull out a mirror

docker run -it centos

(run =(pull start exec))

2. View vim

3. Install a vim 

yum install vim

 

 4. Exit the container

exit

 5. Submit the container


Now the image generated according to the running container is still locally, and the following needs to be submitted and pushed to the private server Harbor

 

Fourth, push the image to Harbor

Start Harbor

It can also be started by executing install.sh.

You can see that docker- compose.yml knows that docker-compose is used, and the background startup can be used to start the harbor.

 Stop container

docker-compose stop

Start the container in the background

docker-compose up -d

Log in to Harbor

docker login  -u 用户名 -p 密码

For example:

docker login --username=cheergoivan registry.cn-hangzhou.aliyuncs.com

Possible error issues

[root @ K8S-Master ~] # Docker the Login 192.168.59.128
the Username: ADMIN   
Password:
Error daemon from the Response: the Get https://192.168.59.128/v2/: Dial tcp 192.168.59.128:443: Connect: Connection refused The
said here The connection was refused because I deployed the harbor using http, here is https:// for access, all errors are reported

Then the solution to this problem is actually under the /etc/docker/daemon.json file

You can log in by adding authentication to the private warehouse

[root@k8s-master ~]# vim /etc/docker/daemon.json

{
        "registry-mirrors": ["http://f1361db2.m.daocloud.io"],
        "insecure-registries": ["192.168.59.128"]
}

重启docker
[root@k8s-master ~]# systemctl restart docker

Log in, here it says that you have logged in. The problem is solved
[root@k8s-master ~]# docker login 192.168.59.128
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Visit http://192.168.59.128/ to log in to Harbor

 

1. Tagging

 docker tag dkcentos:latest 192.168.59.128/dukang/dukcentos:latest

2. Push

docker push 192.168.59.128/dukang/dukcentos


Go to the private server Harbor to check whether the uploaded image is OK 

Note that you can see here: Push format

3. Delete local mirrors (local useless mirrors can be deleted)

(Ensure that the container corresponding to the image is stopped)

docker rmi .........

Unable to delete mirror multiple repositories

Reason: For the deleted ImageID, there are multiple REPOSITORY name references. Delete by mirror name.

Reference article  https://blog.csdn.net/JackLiu16/article/details/80581709

4. Pull the image

docker pull 192.168.59.128/dukang/dukcentos:latest

 

to sum up:

Mirror creation

The docker build  command is used to create an image using Dockerfile.

Use the Dockerfile in the current directory to create an image with the label runoob/ubuntu:v1.

docker build -t runoob/ubuntu:v1 . 

docker commit: Create a new image from the container.

将容器a404c6c174a2 保存为新的镜像mymysql:v1 ,并添加提交人信息和说明信息。
docker commit -a "runoob.com" -m "my apache" a404c6c174a2  mymysql:v1 
  • -a: Submitted mirror author;

  • -c: Use Dockerfile instructions to create a mirror;

  • -m: description text when submitting;

  • -p: When committing, pause the container.

Harbor related

1. Log in

docker login http://xxxxx.com

2. Log in to the private hub to create a project

   For example, the project is called: abc-dev

2. Tag the image

  docker tag 2e25d8496557 xxxxx.com/abc-dev/arc:1334

  2e25d8496557: IMAGE ID, can be viewed with docker images

  xxxxx.com: Private hub domain name

  abc-dev: project name

  arc: mirror name

  1334: Mirror version number

4. Push

  docker push xxxxx.com/abc-dev/arc:1334  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Coder_Boy_/article/details/110312431