Docker is an extremely popular containerization tool that makes it easy to create, deploy, run applications in containers.
# build an image with some version
docker build -t someapp:version .
# build fresh without cache
docker build --no-cache -t someapp:version .
# detach and run
docker container run -d --name someapp -p 5000:5000 someapp:version
# detach and interactive
docker container run -d -it --name someapp -p 5000:5000 someapp:version
# show containers
docker ps
# show container even stopped ones
docker ps -a
docker container stop|rm|run
docker image ls|rm
# interactive container
docker exec -it containerid /bin/sh; exit
# following the logs
docker logs -f appname
# for mounting your code directory into the container
docker run -it --mount "type=bind,source=$(pwd),target=/usr/src/app" -d --name omega-blog -p 80:80 omega-blog:latest
docker run -it --mount "type=bind,source=$(pwd),target=/usr/src/app" -d --name stock_market_dashboard -p 3000:3000 stock_market_dashboard:latest
# create a new container based on a name and ssh into it directly
docker container run -it ubuntu:latest /bin/bash
# EXAMPLE
# to prune old images
docker image prune
# to prune old containers that are stopped
docker container prune
# remove old container
docker container stop omega-blog && docker container rm omega-blog
# remove old image
docker image rm `docker image ls | grep omega-blog | awk '{print $3}'`
# build new image
docker image build --no-cache -t omega-blog:latest .
# running with docker
docker run -it --mount "type=bind,source=$(pwd),target=/usr/src/app" -d --name omega-blog -p 80:80 omega-blog:latest
# to pass an environment file
docker run --env-file .env-doc-dev -it --mount "type=bind,source=$(pwd),target=/usr/src/app" -d --name iot-dashboard -p 9000:9000 iot-dashboard:latest
# to look at logs and follow
docker logs -f omega-blog
# actual codes to run
docker image build --no-cache -t iot-dashboard:latest .
docker run --env-file .env-doc-dev -it --mount "type=bind,source=$(pwd),target=/usr/src/app" -d --name iot-dashboard -p 9000:9000 iot-dashboard:latest
docker logs -f iot-dashboard
# to restart the container
docker container restart iot-dashboard
# to stop and rm the container
docker container stop iot-dashboard && docker container rm iot-dashboard
# to restart all containers
docker restart $(docker ps -a -q)