Common instructions for images and containers in docker

table of Contents

1. Docker introduction

Two.Docker mirror operation

Three.Docker container operation


1. Docker introduction

Docker is a package of Linux containers, providing a simple and easy to use container interface. On the basis of containers, Docker has further encapsulated, from file system, network interconnection to process isolation, etc., which greatly simplifies the creation and maintenance of containers. This makes Docker technology more portable and faster than virtual machine technology. Using dockers can easily manage different versions of images and previously released containers, etc.

Three basic concepts of docker

  • Images: A special file system that can be understood as an installation package, but it contains more information than an installation package. The image contains the programs, libraries, resources, configuration and other files required by the container to run, as well as some configuration parameters. . The image does not contain any dynamic data, and its content will not change after it is built.
  • Container (container): can be understood as a process, the instance that runs the image, can be created, started, stopped, deleted, etc.
  • Repository: A place to store images, similar to a maven library. The built image can be placed in a public image library on the public network, or in a private library built locally. Official library address: https://hub.docker.com

 

Two.Docker mirror operation

2.1 docker searches for a software image: docker search

docker search nginx

The result is as follows:

2.2 docker image pull: docker pull 

When docker installs the image, the default is to install the latest version of the image. If you need to specify the installation version, add the version number after the image name, similar to this [imageName: version number]

# 默认拉取最新的版本latest
docker pull redis

#拉取某版本的镜像:docker pull nginx:版本号

Take redis as an example:

2.3 docker view the image that has been pulled: docker images

[root@localhost yangshilei]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ae2feff98a0c        12 days ago         133MB
redis               latest              ef47f3b6dc11        2 weeks ago         104MB

2.4 Docker image deletion: docker rmi image name

[root@localhost yangshilei]# docker rmi redis
Untagged: redis:latest
Untagged: redis@sha256:0f724af268d0d3f5fb1d6b33fc22127ba5cbca2d58523b286ed3122db0dc5381
Deleted: sha256:ef47f3b6dc11e8f17fb39a6e46ecaf4efd47b3d374e92aeb9f2606896b751251
Deleted: sha256:e7b97696179ae52f99c8f6461f3f941b57c17773dc6e6ea1b1f80c73c123e45b
Deleted: sha256:801f8402e1252a3ea833fd913662681b83fe991dac17fcab63fee395d293816f
Deleted: sha256:263e9403c2490ca4297aa92872fbc2bc6a90ef5131da4846ecda24577678f7da
Deleted: sha256:888cb204a0d4130e3f91638f50d31f1934b62bcf3a312a4b3f8e921930c22640
Deleted: sha256:54bfccba7f0a8056bd6e1e66db469726395627e37eac6d41db37e71fc1a2536d
[root@localhost yangshilei]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ae2feff98a0c        12 days ago         133MB

Three.Docker container operation

3.1 docker run container: docker run --name container name -p external port number: port number in the container -d image name, -t returns a terminal

docker run --name nginx-test  -p 8081:80 -d nginx

/# 或者自己搭建的java项目类似如下启动
docker run -p 8080:8080 -t haiyang/docker-study

3.2 View the running container: docker ps

# 查看运行中的容器
[root@localhost yangshilei]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c425e8b90a69        nginx               "/docker-entrypoint.…"   5 hours ago         Up 8 minutes        0.0.0.0:8081->80/tcp   nginx-test

# 停止运行的容器
[root@localhost yangshilei]# docker stop c425e8b90a69
c425e8b90a69

# 查看运行中的容器
[root@localhost yangshilei]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

# 查看所有容器,运行中和停止的
[root@localhost yangshilei]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c425e8b90a69        nginx               "/docker-entrypoint.…"   5 hours ago         Up 8 minutes        0.0.0.0:8081->80/tcp   nginx-test

The columns of the container are described as follows:

3.3 Stop the container: docker stop container id

[root@localhost yangshilei]# docker stop c425e8b90a69
c425e8b90a69

3.4 Start the stopped container: docker start stop container id

[root@localhost yangshilei]# docker start c425e8b90a69
c425e8b90a69
[root@localhost yangshilei]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c425e8b90a69        nginx               "/docker-entrypoint.…"   5 hours ago         Up 3 seconds        0.0.0.0:8081->80/tcp   nginx-test

3.5 Enter the container: docker exec -it container id / directory

[root@localhost yangshilei]# docker exec -it c425e8b90a69 /bin/bash
root@c425e8b90a69:/# pwd
/
root@c425e8b90a69:/# 

3.6 Exit the container: exit

 root@c425e8b90a69:/# exit
exit
[root@localhost yangshilei]# 

 

Worked, I will write so much today, and I will continue to add later. . . . . .

 

 

Guess you like

Origin blog.csdn.net/qq_37488998/article/details/111868004