How to run a Docker Container
- Tag image <dockerhub-username>/web with web1
docker image tag <dockerhub-username>/web1 web1
- Remove docker image with <dockerhub-username>/web1
docker image rm <dockerhub-username>/web1
- Run your docker image, check in browser by putting Public IP followed port 5000
docker container run -it -p 5000:5000 -e FLASK_APP=app.py web1
-e =execute command in Docker -p = Define container & host port -it = interactive mode
- Remove container manually using container ID
docker container rm [container id]
- Again run container
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm --name web1 web1
-e =execute command in Docker -p = Define container & host port -it = interactive mode -rm = removes container when it stopped --name = Define container name
- Check for docker image
docker container ls -a
- Again run container
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm --name web1 -d web1
-e =execute command in Docker -p = Define container & host port -it = interactive mode -rm = removes container when it stopped --name = Define container name -d = Run container is background
- Check container logs
docker container logs web1
- Check container logs in trailing mode
docker container logs -f web1
- Check container metrics
docker container stats
- Run a new container
docker container run -it -p 5000 -e FLASK_APP=app.py --rm --name web1_2 -d --restart on-failure web1
-e =execute command in Docker -p = Define container & host port -it = interactive mode -rm = removes container when it stopped --name = Define container name -d = Run container is background --restart on-failure = restarts the container when daemon or host fails and back online
- Stop the containers
docker container stop web1
docker container stop web1_2