Docker itself does not provide a specific command to rollback to a previous version of a container or image. However, you can achieve a similar effect by using Docker’s tagging and versioning system. Here are the steps to do that:
1. Tag your images: Whenever you build a new image of your application, tag it with a version number.
\`\`\`bash $ docker build -t myapp:1.0 . \`\`\`1. Run the specific versions: When you run a container from the image, specify the version that you want to use.
\`\`\`bash $ docker run -d -p 80:80 myapp:1.0 \`\`\`1. Change versions: If you want to rollback to a previous version, you can simply stop the current container and start a new one from the older image.
\`\`\`bash $ docker stop myapp\_container $ docker rm myapp\_container $ docker run -d -p 80:80 myapp:0.9 \`\`\`This method needs that you keep versions of your application as separate Docker images and takes care about not deleting old ones.
Alternatively, you can create an specific system inside your application that allows rollbacks, and put it inside your container. Or you can use solutions like Kubernetes that provides a more complex system to manage containers and versions.