This is the 27th day of my participation in the August More Text Challenge

If ❤️ my article is helpful, welcome to like, follow. This is the biggest encouragement for me to continue my technical creation. More previous articles in my personal column

Docker basic entry, you can try to package docker image and write dockerfile. But before we get there, let’s look at some basic concepts

Docker mirror

Docker Hub warehouse has two types of warehouse, the user warehouse and the top-level warehouse. The user warehouse is created by Docker users, and the top-level warehouse is managed by docker internal people. Repository is stored in the image file, then the question comes, how to create the image?

There are two ways to build a Docker image:

  1. usedocker commitCommand.
  2. usedocker buildCommands andDockerfileFile.

Instead of using the Docker commit command, you should use a more flexible and powerful Dockerfile to build the image.

1. Create a centos image

Docker pull centos Create a container based on the centos image after pulling the centos image

View existing images on the server by using the docker images command

Docker run -dit -p 400:8080 centos Specifies the image name or ID

Create a container based on a centos image to run in the background and map port 4000 of the server to port 8080 of the container

2. Upload the JDK, Tomcat installation package, and Web project to the image

Docker cp /usr/local/JDK installation package Container name: container address docker cp /usr/local/Tomcat installation package container name: container address docker cp /usr/local/web Project container name: container address 1

3. Enter the container and perform operations

Enter the container by using the docker attach container name or ID command

Installing the JDK and Tomcat is the same as installing it on Linux. You can use the container as a Linux virtual machine and start the Tomcat service

4. Verify

Enter http://server IP address :4000 in the browser. If the Tomcat page is displayed, it succeeds

5. Pack the container as an image

Docker commit -a “runoob.com” -m “my apache” container name or ID Package image name: label OPTIONS: -a: commit image author; -c: use the Dockerfile command to create an image. -m: Description of submission; -p: Suspends the container at commit time.

6. Upload to your DockerHub

If you don’t have a Docker account, sign up for one at cloud.Docker.com. Write down your user name. Log in to the Docker public registry on your local computer.

docker login
Copy the code

Then, after the image is marked with a Docker tag, docker pushes it to the DockerHub. You can download it again later when you need it