How to create your own Docker image and upload it to Dockerhub

How to create your own Docker image and upload it to Dockerhub

1. First register your own dockerhub account, registration address: https://hub.docker.com

2. Log in to your account on the Linux server: docker login --username=qiaoyeye

3. Find the image you want on https://hub.docker.com/

4. Pull the image to local: docker pull centos

5. Prepare jdk and tomcat software locally, decompress them and put them into the server

6. Create a new Dockerfile file, pay attention to case sensitivity

#---------------------------------------------------------------------

#This is a comment#Use the base image centos:latest

FROM centos:latest
#Specify the image creator information MAINTAINER qiaoyeye <<A href="mailto:[email protected]@163.com" rel="external nofollow" >[email protected]>

#Switch the image directory and enter the /usr directory (the basic image is a Linux system, you can refer to Linux to view the corresponding directory)
WORKDIR /usr

#Create a java directory under /usr/ to store jdk
RUN mkdir java

#Switch the mirror directory to /usr/java
WORKDIR /usr/java

#Create a jdk directory under /usr/java to store jdk files RUN mkdir jdk

#Switch the mirror directory to /usr/java/jdk
WORKDIR /usr/java/jdk

#Add all files in the host's jdk directory to the mirror's /usr/java/jdk directory ADD jdk /usr/java/jdk

#Switch the mirror directory to /opt
WORKDIR /opt

#Create a tomcat directory under /opt to store tomcat files RUN mkdir tomcat

#Add all files in the host machine's tomcat directory to the mirror's /opt/tomcat directory ADD tomcat /opt/tomcat

#Set environment variable ENV JAVA_HOME=/usr/java/jdk
ENV JAVA_BIN=/usr/java/jdk/bin
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

#Set the operation to be performed when the container starts CMD /opt/tomcat/bin/catalina.sh run

#---------------------------------------------------------------------

7. Make a mirror: docker build -tqiaoyeye/centos:latest.

Note the last dot

8. View the created docker images

9. Upload the image value to the hub warehouse.

docker pushqiaoyeye/centos:latest

10. If the uploaded image is not your dockerhub and the image name is: Docker ID/warehouse name, first use: docker tag image ID Docker ID/warehouse name: new tag name (tag)

sudo docker tag bd213262aa2cqiaoyeye/centos:latest

11. After the upload is successful, log in to your dockerhub and check

PS: How to upload the image to Alibaba Cloud? ? ?

The steps for uploading the image to Alibaba Cloud are the same as above. Detailed official instructions for the meal card: https://cr.console.aliyun.com/repository/cn-beijing/qiaoyeye/test1/details

1. Log in to Alibaba Cloud Docker Registry

$ sudo docker login --username=乔叶叶registry.cn-beijing.aliyuncs.com

The username used to log in is the full name of the Alibaba Cloud account, and the password is the password set when activating the service.

You can change your login password on the product console home page.

2. Pull the image from the Registry

$ sudo docker pull registry.cn-beijing.aliyuncs.com/qiaoyeye/test1:[image version number]

3. Push the image to the Registry

$ sudo docker login --username=乔叶叶registry.cn-beijing.aliyuncs.com$ sudo docker tag [ImageId] registry.cn-beijing.aliyuncs.com/qiaoyeye/test1:[image version number]$ sudo docker push registry.cn-beijing.aliyuncs.com/qiaoyeye/test1:[image version number]

Please replace the [ImageId] and [Image version number] parameters in the example according to the actual image information.

4. Choose the appropriate image repository address

When pushing an image from ECS, you can choose to use the intranet address of the image repository. The push speed will be improved and will not consume your public network traffic.

If the machine you are using is located in a classic network, use registry-internal.cn-beijing.aliyuncs.com as the domain name of the Registry to log in and as the image namespace prefix.

If the machine you are using is located in a VPC network, use registry-vpc.cn-beijing.aliyuncs.com as the domain name to log in to the Registry and as the image namespace prefix.

5. Examples

Rename the image using the "docker tag" command and push it to the registry via the private network address.

$ sudo docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEregistry.aliyuncs.com/acs/agent 0.7-dfb6816 37bb9c63c8b2 7 days ago 37.89 MB$ sudo docker tag 37bb9c63c8b2 registry-vpc.cn-beijing.aliyuncs.com/acs/agent:0.7-dfb6816

Use the "docker images" command to find the image and change the domain name in the image name to the registry private network address.

$ sudo docker push registry-vpc.cn-beijing.aliyuncs.com/acs/agent:0.7-dfb6816

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker image analysis tool dive principle analysis
  • How to create Apache image using Dockerfile
  • Docker image access to local elasticsearch port operation
  • Multi-service image packaging operation of Dockerfile under supervisor
  • Docker image compression and optimization operations

<<:  An article teaches you how to implement VUE multiple DIVs and button binding enter events

>>:  Steps to solve the MySQL 8.0 time zone problem

Recommend

Pure js to achieve typewriter effect

This article example shares the specific code of ...

Teach you how to implement a react from html

What is React React is a simple javascript UI lib...

How to prohibit vsftpd users from logging in through ssh

Preface vsftp is an easy-to-use and secure ftp se...

Detailed explanation of Docker daemon security configuration items

Table of contents 1. Test environment 1.1 Install...

How to monitor the running status of docker container shell script

Scenario The company project is deployed in Docke...

Summary of constructor and super knowledge points in react components

1. Some tips on classes declared with class in re...

Detailed explanation of MySQL transaction processing usage and example code

MySQL transaction support is not bound to the MyS...

How to restore single table data using MySQL full database backup data

Preface When backing up the database, a full data...

An elegant way to handle WeChat applet authorization login

Preface When the WeChat mini program project invo...

Make a nice flip login and registration interface based on html+css

Make a nice flip login and registration interface...

Some questions about hyperlinks

<br />I am very happy to participate in this...

About Zabbix forget admin login password reset password

The problem of resetting the password for Zabbix ...

A brief analysis of the usage of HTML float

Some usage of float Left suspension: float:left; ...