Tips:
Utilize layer caching can reduce image build time
- In Terminal:
docker build -t myapp .
-
Docker Images list:
docker images
-
Run Docker container with Image name or ID:
docker run --name myapp_c myapp
--name myapp_c
< is optional -
Run Docker container with Mapped port on Localhost:
docker run --name container1 -p 4000:4000 -d --rm -v "$(pwd):/app" -v /app/node_modules myapp:nodemon
-d detach > optional : run container in the background?
-v volumn : virtual hard drives managed by Docker. Docker handles storing them on disk
--rm remove after stop
you can use -v option from cli, this facility is not available via Dockerfile
docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash
where host_dir is the directory from host which you want to mount. you don't need to worry about directory of container if it doesn't exist docker will create it.
If you do any changes in host_dir from host machine (under root privilege) it will be visible to container and vice versa.
-
Check Docker process:
docker ps
-
Stop Docker with name or ID:
docker stop myapp_c
-
List stopped containers:
docker ps -a
-
Start Container:
docker start -i <name/id>
-
Docker Image remove:
docker image rm myapp <-f>
-
Docker container remove:
docker container rm myapp_c
-
Docker remove all container, images and volumes:
docker system prune -a
- Run Docker compose
docker compose up
docker compose down <--rmi all -v>
- Push to DockerHub
Step1:docker build -t <userID>/api .
Create Image with userId/file
Step2:docker login -u <name>
||docker login -u <name> -p <password>
Step3:docker push <userId>/api
push with image name