//通过镜像产生一个容器
docker run -p port1:port2 containerName:tag
//启动一个已有的容器
docker start containerID/containerName
//停止一个容器
docker stop containerID/containerName
//重启一个容器
docker restart containerID/containerName
//与一个已经启动的容器进行交互式操作
docker exec -i -t containnerID/containerName /bin/bash
//复制文件到容器中
docker cp src_path containerId:dest_path
容器自启
创建一个容器自启
docker run -p port1:port2 --restart=always containerName:tag
Flag Description
no 不自动重启容器. (默认value)
on-failure 容器发生error而退出(容器退出状态不为0)重启容器
unless-stopped 在容器已经stop掉或Docker stoped/restarted的时候才重启容器
always 在容器已经stop掉或Docker stoped/restarted的时候才重启容器
如果已经启动的项目,则使用update更新:
docker update --restart=always 容器id