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

4 solutions to CSS browser compatibility issues

Front-end is a tough job, not only because techno...

How to write HTML head in mobile device web development

Copy code The code is as follows: <head> &l...

Summary of the differences between get and post requests in Vue

The operating environment of this tutorial: Windo...

JS quickly master ES6 class usage

1. How to construct? Let's review the common ...

How to generate mysql primary key id (self-increment, unique and irregular)

Table of contents 1. Use the uuid function to gen...

How to install mongodb 4.2 using yum on centos8

1. Make a repo file Refer to the official install...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

The hottest trends in web design UI in 2013 The most popular UI designs

Time flies, and in just six days, 2013 will becom...

jQuery implements shopping cart function

This article example shares the specific code of ...

What to do if you forget the initial password of MySQL on MAC

The solution to forgetting the initial password o...

Quickly solve the problem of slow startup after Tomcat reconfiguration

During the configuration of Jenkins+Tomcat server...

How does MySQL achieve master-slave synchronization?

Master-slave synchronization, also called master-...

How to solve the Mysql transaction operation failure

How to solve the Mysql transaction operation fail...

Detailed explanation of Vue project packaging

Table of contents 1. Related configuration Case 1...

Tutorial on installing mysql5.7.36 database in Linux environment

Download address: https://dev.mysql.com/downloads...