docker build .
docker build -t "image-name" .
docker images ls
docker image rm image-name
docker run -p 3000:3000 -d image-name
docker run -p 3000:3000 -d --name container-name image-name
docker ps
docker ps -a
docker exec -it container-name bash
docker rm container-name -f
docker rm container-name -fv
docker run -v %cd%:/app -p 3000:3000 -d --name container-name image-name
docker logs containerID / container-name
docker run -v %cd%:/app -v /app/node_modules -p 3000:3000 -d --name container-name image-name
docker run -v %cd%:/app:ro -v /app/node_modules -p 3000:3000 -d --name container-name image-name
docker run -v %cd%:/app:ro -v /app/node_modules --env PORT=4000 -p 3000:4000 -d --name node-app node-app-image
docker run -v %cd%:/app:ro -v /app/node_modules --env-file ./.env -p 3000:4000 -d --name node-app node-app-image
docker volume ls
docker volume rm volume_id
docker volume prune
docker-compose up
docker-compose up -d
docker-compose down
docker-compose down -v
docker-compose up -d --build
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
docker network ls
docker inspect container-name
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --no-deps service-name
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d -scale node-app=2
docker logs 28docker-node_and_express-node-app-1 -f
-
By Default Docker container can talk to the outside world.
-
But from the outside world no once can talk with our container that is by default due to security mechanism.
-
Outside world means local machine and internet both.
-
docker run -p 3000:3000 -d image-name Here in this command do port forwarding we send the traffic which comes to our machine at port 3000 will be forwarded to container port 3000.
-
Now we are able to talk to our container.
-
number of left to -p is the traffic coming from outside world and the number on right side is the number which our container is expecting.
- In docker we can sync our source code with the docker work dir.
- So we don't have to rebuild our image again as we make changes in our code.
- During build command ve need use -v flag with localPath:ContainerPath
- Here we have use %cd% which automatically fetch the current local path of pour folder.
- /app is the path to folder on container from which we have to sync.
- This -v is bind mount.
- This will sync all the folder.
- To prevent the local folder from over riding the /app dir of our container we use anonymous volume.
- Using another v flag we can mention the anonymous volume.
- -v /app/node_modules this is little hack to bind the node_modules folder with our container.
- All the folder will get sync but it will not touch the node_modules folder of container
- -v %cd%:/app:ro using this command we cannot create file or folder in container from container.
- This is good for security reasons as we don't want that some one change our source code from our local dir.
- The volume which is listed from running the docker volume ls command is the anonymous volume that is created while building up the container.
- docker run -v %cd%:/app:ro -v /app/node_modules --env-file ./.env -p 3000:4000 -d --name container-name image-name
- Here the node_modules folder is preserved us for every time by the docker and that's why the volume is created by the docker.
- We can delete them by running docker volume rm volume_id
- Another command is docker volume prune this will delete the volume which is not in use.
- Docker compose actually helps to run the command.
- We have to create a file in which each step and configuration is mentioned.
- Then just run that file.
- In docker-compose file we have to first mentioned the docker compose version which we are using it.
- Each container in docker-compose file refer as service.
- Docker compose looks for image project_dir-name-of-services.
- Docker compose is not smart we need to tell him when we ant to build it again
- Read documentation for docker compose file.
- In docker compose file when we use a another image then we can use a image property.
- Bind Mount Syncs data with your folder local drive 👉 ./:/app:ro
- Anonymous volume 👉 /app/node_modules
- Named Volume is same as Anonymous volume only we gave a name 👉 mongo-db:/data/db
- We need to declare our named volume in docker-compose file so that another services can also used that volume.
- Bridge and host network comes up with the docker.
- As there is custom networks so we have DNS.
- We can talk to other docker container with the help of DNS.
- If we want that our one container talk to our another container just refer to use service name DNS will resolve it get its IP for us.
- Only applicable to network we create.
- depends on actually helps to spin up the mentioned container first.
- Like we want our mongo container to spin up before the node container so in this case depends on property will help us out.
```
```