Create mirror (update and build mirror)

Create a mirror

Sometimes the image downloaded from the Docker mirror warehouse does not meet our requirements. At this time, you can encapsulate your own image based on this image (base image)

Two ways:

  • Update the image: use the docker commit command
  • Build the image: use the docker build command, you need to create a Dockerfile file

Update mirror

First use the basic image to create a container, then modify the container, and finally use the commit command to submit as a new image

step:

  1. Create a container based on the base image
 docker run --name tomcat -p 8080:8080 -d tomcat
  1. Modify the container
 docker exec -it ac848f0af7d8 /bin/bash
cd webapps/ROOT 
rm -f index.jsp 
echo welcome to tomcat > index.html 
exit
  1. Submit as a new image, syntax: docker commit m="description message" a="author" container id or container name image name: tag
docker commit -m="test" -a="v_lysvliu" ac848f0af7d8 itany/tomcat:v1
  1. Run the container with the new image
docker run ­­name tomcat_v1 ­p:8080:8080 ­d itany/tomcat:v1

Build image

Automatically build a mirror based on the Dockerfile file.
Dockerfile is a text file that contains all the commands for creating a mirror. Use the docker build command to create a mirror based on the contents of the Dockerfile.

step:

  1. Create a Dockerfile file vi Dockerfile
# 基础镜像 
FROM tomcat 

# 作者 MAINTAINER [email protected] 

# 执行命令 
RUN rm -­f /usr/local/tomcat/webapps/index.jsp 
RUN echo "welcome to tomcat!" > /usr/local/tomcat/webapps/ROOT/index.html
  1. Build a new image, syntax: docker build f Dockerfile file path t image name: tag command execution context
docker build -­f Dockerfile -­t itany/tomcat:v2
  1. Run the container with the new image
docker run ­p 9999:8080 ­d itany/tomcat:v2

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/113009374