Docker---3.Docker image usage articles

1 List the local image list

docker images

Insert image description here

We can see from the picture that there are two ubuntuimages in it, one is the latest version and the other is the 15.10 version.

The same warehouse source can have multiple TAGs, representing different versions of the warehouse source. If we can use it at runtime to use a REPOSITOORY:TAGspecific image, if we do not add a specific one, the version TAGwill be used by default . latestFor example:

 docker run -t -i ubuntu:15.10 /bin/bash 

inside ubuntu:15.10.

Property description :

  • REPOSITORY: Represents the warehouse source of the image.

  • TAG: The tag of the image.

  • IMAGE ID: Image ID.

  • CREATED: Image creation time.

  • SIZE: Image size.

Origin of the image: If the image is not downloaded but does not exist when running the container, it will be downloaded from the Docker Hub public image source by default.

2 Add local image

docker pull 镜像名[版本号], used by default if there is no version number latest.

3 Find the remote mirror

  • You can get the image from the public image URL .
  • docker search 镜像名, obtain related image information.

Insert image description here

Parameter Description:

  • NAME: The name of the mirror warehouse source

  • DESCRIPTION: Description of the image

  • OFFICIAL: Is docker officially released?

  • stars: Similar to the star in Github, it means likes and likes.

  • AUTOMATED: Automatically built.

4 Delete the local image

docker rmi 镜像名, the image name can be fromdocker images

docker rmi 镜像名

Insert image description here

5 Update the local image

step:

  • First open the container with the image, and then update it in the container.
  • After the update is completed, exit the container and use docker committhe modified container commit to save a new image.
 docker commit -m "upgrade:使用apt-get update进行更新" -a="runoob" cfc3dadf9bd5 runoob/ubuntu:v2

Insert image description here

Parameter Description:

  • -m: Submitted description information

  • -a: Specify the image author

  • cfc3dadf9bd5: Container ID

  • runoob/ubuntu:v2: Specify the target image name to be created

6 Create an image

docker buildcommand to create an image from 0 based on the Dockerfile .

  • Create a Dockerfile

For example:

FROM centos:6.7
LABEL maintainer="swrici"

RUN     /bin/echo 'root:123456' |chpasswd
RUN     useradd runoob
RUN     /bin/echo 'runoob:123456' |chpasswd
RUN     /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local
EXPOSE 22
EXPOSE 80
CMD /usr/sbin/sshd -D
- 每个指令前缀都必是大写。
- 每一个指令都会在镜像上创建一个新的层,
- 第一条FROM,指定使用哪个镜像源
- RUN 指令告诉docker 在镜像内执行命令,安装了什么

Insert image description here

  • After creation, execute docker build the command
docker build -t runoob/centos:6.7 .

Parameter Description:

  • -t :Specify the target image name to be created

  • .: The directory where the Dockerfile file is located. You can specify the absolute path of the Dockerfile.
    Execution results:

Insert image description here

If it is a Linux subsystem under Windows, error code 139 may appear during execution.

Solution 1

  • Create a new file in the user directory .wslconfig. For example: C:\Users(username).wslconfig
  • The file content is:
    [wsl2]
    kernelCommandLine = vsyscall=emulate
  • Restart the computer

7 Set image tag

docker tag 镜像ID

docker tag 97cdc68827e1 runoob/centos:dev
  • 97cdc68827e1: Image ID
  • runoob/centos: Mirror source name (repository name)
  • dev: new tag name (tag).

  1. Quote: https://blog.csdn.net/i2blue/article/details/119035406 ↩︎

Guess you like

Origin blog.csdn.net/Srwici/article/details/125610488