My Notes


Manjush's Blog Docker Commands

Docker Image Vs Container

 

* An image is the application we want to run

* A container is an instance of that image running as a process

* You can have many containers running of the same image

* Dockers default image registry is called Docker Hub (hub.docker.com)

 

Docker Commands

 

$ docker  -  > Shows list of commands

Divided into two

* Management Commands

- Management Commands format 

$ docker <command> <sub command> [options]

example : docker container run

old format : docker run

Note : both format works

* Commands

$ docker info  -  > Shows most configuration values for the engine

 

$ docker container run --publish 80:80 nginx

* Download image nginx from Docker hub

* Started a container from that image 

* Opened port 80 on the host IP

* Routes that traffic to the container IP, port 80.

$ docker container run --publish 80:80 --detach nginx

detach tells docker to run at the background

$ docker container ls

to list all  containers

$ docker container ls -a

$ docker container stop <first few digits of container id>

stop docker container with a particular id

run Vs start

docker container run - always starts a new container

docker container start - starts a stopped container

 

$ docker container run --publish 80:80 --detach --name webhost nginx

- a docker container with a specific name

$ docker container logs <container name>

- to view the logs of a container

$ docker container top <container name>

- Display the running processes of a container

$ docker container rm <first few digits of container1> <first few digits of container2>

- to remove multiple files at a time

$ docker container rm -f <first few digits of container>

- to forcefully remove the container

$ docker container run --publish 80:80 --detach --name webhost -d nginx:1.11 nginx -T

- for a specific version of nginx

 

Containers are not mini VM's 

* They are just processes

* Limited to what resources they can access

* Exit when process stops.

 

Getting a shell inside containers

$ docker container run -it --name proxy nginx bash

* if run with -it will give a terminal inside the running container

$ docker container start -ai <container name>

To Run a command in a running container use exec

$ docker container exec -it mysql bash

exec wont affect the main process