Demo of docker deployment process

Step 1: Create a container and enter the container

#本例中我们创建一个基于ubuntu系统的容器,并将该容器命名为myubutu
docker run -it --name myubuntu ubuntu /bin/bash

Step 2: After entering the container, install the required environment

#更新系统的软件源
apt update

#安装python3
apt install python3

#安装pip工具
apt -y install python3-pip

#安装flask
pip install flask

Step 3: Upload the files on the host to the container

#注意:这一步需要在宿主的终端中进行执行,本例中是将宿主的/root目录中的1.py文件上传到名字为mybuntu容器中的/home目录中
docker cp /root/1.py myubuntu:/home

Step 4: Exit the container

exit

Step 5: Create a new image based on the container, named myimage

docker commit myubuntu myimage

Step 6: Export and package the new image obtained in the previous step, the package name is myimage.tar

docker save -o myimage.tar myimage

Step 7: Upload the compressed package obtained in the previous step to the remote server for others to use

Step 8: Assuming that someone else got the compressed package, and the docker container is also installed in this person's system environment, then he can import the compressed package, compress and decompress it, and then use the image

 docker load -i myimage.tar

Step 9: Create a new container based on the image, let it run in the background, the container name is hisubuntu, and use the local network, ie –network=host

docker run -dit --name hisubuntu --network=host myimage /bin/bash

Step 10: Enter the container, you can use it directly, no need to configure the environment

docker exec -it hisubuntu /bin/bash

Note: The container shares a network card information with the host during the running process

Guess you like

Origin blog.csdn.net/m0_56192771/article/details/123765772