Docker study notes (3) containers and images

I. Container articles

We can enter docker to view all the commands about Docker, and I won't say anything more specific, it's meaningless.

1. Port Settings

The following example is to run a web application by running a python Flask application

docker pull training/webapp
docker run -d -P training/webapp python app.py    #-d:让容器在后台运行 -P:网络端口映射到主机

At this time, we enter docker ps and we can see more port information, which means that port 5000 of docker is mapped to port 32768 of our host.

At this time, we can access through the browser

We can also set the designated port

docker run -d -p 5000:8080 training/webapp python app.py

(1) Note here ******* -P is to randomly map the internal port of the container to the host port, and -p is to map it to the specified host port

(2) Another point to note is that the default docker binding is the tcp port. If we want to bind the port, add / udp after the port number , eg:

docker run -d -p 5000:5000/udp training/webapp python app.py

If you want to bind the ip address and add it after -p / P, eg:

docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py

In addition to docker ps and docker port ID / name, you can also view the port mapping

2. Other commands

docker run -d -P --name yyk training/webapp python app.py #将容器名称自主定义为yyk

docker logs ID / name can view container logs

docker top can view the container process

docker inspect View Docker's low-level information (container configuration and status information)

docker rm ID / name delete container (must stop the corresponding container first)

docker ps -l  queries the last container created

docker start / restart / stop ID / name    start / restart / stop container

2. Mirror articles

       First of all, when we run the container, if the required image is not found locally, docker will automatically download it from its image warehouse. The default is the DockerHub public image source. Many friends say that they need to change the source. , The individual said that there is no source change, the speed is OK, here depends on the individual, if you need to change the source, please solve it yourself.

1. Get a new image

查找镜像      docker secrch 镜像名
拉取镜像      docker pull 镜像名称  eg: docker oull ubuntu:18.10
运行镜像      docker run 镜像名

2. Create your own image

(1) Update the image from the container that has been created, and then submit it

创建一个Ubuntu:18.10的镜像   docker run -t -i ubuntu:18.10 /bin/bash
使用apt-get update更新,然后exit退出容器
此时记住我们的容器ID,然后通过命令  docker commit -m="update already" -a="yyk" 容器ID root/ubuntu:A2

Parameter Description:

-m: description information of this image; -a: author of this image; root / ubuntu: A2: name of the created image

 

(2) Use the Dockerfile instruction to create a new image

First create a Dockerfile file, and then enter the content (here is too lazy to not write, there is no pit, after all, it is just an essay, there are online), pay attention to every instruction is capitalized, and finally use docker build -t image. To build an image (note the last point)

 

The last is to use the image to create the container, docker run -t -i image name / bin / bash, docker will then return to let us enter the ID set before, and then it can be used

 

3. Mirror view and its label

使用docker images列出本地所有镜像

Parameter Description:

REPOSITORY: mirrored warehouse source

TAG: Mirrored tags

CREATED: Mirror creation time

The image tag is just like the version, so we can customize our own tag, docker tag image ID root / ubuntu: tag name

 

 

____________________________________________________________________________________________________

This is the end of the Docker notes, the rest of the installation of Barbara is all routines, bye, docker!

Published 25 original articles · Liked 14 · Visits 5445

Guess you like

Origin blog.csdn.net/qq_40568770/article/details/87257606