By default, Docker looks for a file named Dockerfile when building images.
docker build -t express-prod-i .
-t
- Optionally tag, or name a docker image to avoid referring to the auto-generated ID (e.g. 50e8dde7e180).
- Look for the Dockerfile in the current directory-f
- Override default Dockerfile name
- RUN - Is an image build step
- CMD - Is a command the contanier executes when you launch the built image
docker images
docker history express-prod-i
docker run -d --name express-prod-app -p 7000:3000 -v $(pwd):/var/app express-prod-i
-d
- Detached mode. Don't tie up current terminal.--name
- Name the container-p
- Map local host port7000
to the exposed container port3000
express-prod-i
- The image we want to generate and run-v
- Mount a volume on the host machine.$(pwd):/var/app
mounts the present working directory on the host machine to/var/app
on the container
docker ps
- Show running containersdocker ps -a
- Show ALL containers. Useful when something goes wrong and the container stops.
docker logs hackershall-prod-app
- Check thehackersall-prod-app
container logs
docker exec -it hackershall-prod-app /bin/sh
- Access a bash shell on a running container
-it
- interactive terminal
docker inspect express-prod-app
- Shows volume and mount information within
"Mounts"
- Shows volume and mount information within
docker stop express-prod-app
docker start express-prod-app
docker rm express-prod-app
- Delete theexpress-prod-app
containerdocker rm $(docker ps -a -q)
- Delete ALL containers
docker rmi express-prod-i
- Delete theexpress-prod-i
imagedocker rmi $(docker images -q)
- Delete ALL images
- You can specify patterns to ignore when building an image within a
.dockerignore
file
docker system prune
- Remove stopped containers
- Remove images without any containers
- Remove orphaned volumes
docker-compose build
- Build or rebuild servicesdocker-compose up
- Create and start containersdocker-compose start
- Start servicesdocker-compose stop
- Stop servicesdocker-compose down
- Stop and remove containers, networks, images, and volumes