Docker usage specific process

1. Create and start containers

docker run

 -i: indicates running the container

-t: Indicates that the container will enter its command line after it is started. After adding these two parameters, you can log in when the container is created. i.e. allocate a pseudo terminal

--name: Name the created container (the container name cannot be repeated)

-v: Indicates the directory mapping relationship (the former is the host directory and the latter is the container directory). Multiple -v can be used to map multiple directories or files. Note: It is best to do directory mapping, make changes on the host, and then share it to the container.

-p: When indicating port mapping, the former is the host port and the latter is the mapped port in the container. You can use multiple -p for port mapping.

Commonly used commands: docker run -it image name Create a container in interactive mode (-it can be abbreviated to -it). The reason why it is called interactive is that you directly enter a pseudo terminal after running this command.

After docker run, the container of the image is created. The system will automatically assign a container id to the container. If the container name is not specified, then a random name will be used. Generally, in order to distinguish the container and facilitate the startup of the container next time, -- The name parameter customizes the container name; for example: docker run --name=pymesh pymesh/pymesh

Note: If you do not add the -i parameter after docker run, the container is only created and not started.

2. Start the container

docker start

docker start container name to start the corresponding container.

3. Enter the container

docker exec

Commonly used commands: docker exec -it container name/bin/bash

Enter the pseudo terminal bound to the container. After entering, the file directory of the previous terminal will not be accessible under this container, so in order to access the relevant directories between the pseudo terminal and the terminal, you can use the -v parameter to mount the directory when creating the container.

For example:

docker run -di -v /home/rui/work/csy:/home/csy --name=pymesh pymesh/pymesh

docker run -di -v host directory:container directory--name=container name image name

When exiting the container, enter the command exit.

4. Close the container

docker stop container name

Guess you like

Origin blog.csdn.net/weixin_54106682/article/details/129890255