且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Docker交互模式和执行脚本

更新时间:2023-12-04 19:21:52

My way of doing it is slightly different with some advantages. It is actually multi-session server rather than script but could be even more usable in some scenarios:

# Just create interactive container. No start but named for future reference.
# Use your own image.
docker create -it --name new-container <image>

# Now start it.
docker start new-container

# Now attach bash session.
docker exec -it new-container bash

Main advantage is you can attach several bash sessions to single container. For example I can exec one session with bash for telling log and in another session do actual commands.

BTW when you detach last 'exec' session your container is still running so it can perform operations in background