Docker
Commands

Command

docker build [-tag or -t] node-docker .


To create & run Nginx Web Server

#| —detach means run in background  |> it will download the nginx server from hub and run in 5000
docker container run  publish 5000:80 —detach —name web_host nginx
 
#| 80 port serve in  5000
docker run -p 5000:80 nginx
#| -a is for show images which is not still running
docker container ls -a
#| just put unique value of start it will find that.
docker container stop 435
#| -f is use to remove running container
docker container rm -f 324 543 543
# at the end of command (name of a image)
docker container logs

short forms | command detail

-d for —detach | to run container in bg

-p for —port | to set port

-e | to set env variable

logs | to see logs of the specific container


What’s going on in containers :

docker container top # process list in one container
docker container inspect # details of one container config
docker container stats # performance stats for all containers

Docker networks : Cli

docker network ls  #| Show networks
docker network inspect #| Inspect a network
 
docker network create  driver #| Create a network
docker network connect #| attach a network to container
 
docker network disconnect #| detach a network from container
 

docker networks : Default Security

  • Create your apps so frontend/backend sit on same docker network
  • their inter-communication never leaves host
  • all external exposed ports closed by default
  • You must manually expose via -p, which is better default security!
  • This gets even better later with swarm and overlay networks

To run container in specific network

docker container run -d —name new_nginx —network my_first_network nginx

Bridge networks are commonly used for most container communication within a single Docker host. Overlay networks are useful in distributed environments where containers need to communicate across multiple hosts or Docker Swarm nodes. Host networks are employed when high performance and direct access to the host's network stack are crucial.


docker ps -a | running container

docker images | to check images

For Push

docker push

then include tag + repo name and tag name (1.0)