Sunday, February 4, 2018

Docker commands

#Build: To build, create a Dockerfile in a directory and inside the directory run the following command: (Change NAME with your image name)
docker build -t NAME .

#List Docker Images:
docker images

#Remove Docker Image
docker image rm -f ID

#Run: To run the container image called NAME with following options:
1. Map the host port 80 with container port 80
2. Limit memory to 1000MB
3. Limit CPU = 1
4. Assign name = NAME
--use the following command:
docker run --rm -it -p 80:80 -m 1000m --cpus=1 --name=NAME NAME

#List Docker processes
docker ps

#See a live stream of container(s) resource usage statistics (like top)
docker container stats

#Display the running processes of a container (one shot)
docker container top NAME

#Check iptables for port mapping:
sudo iptables -t nat -L -n

#Commit Container or take a snapshot while running:
docker commit NAME NAME:run


Dockerfile

#Create a Dockerfile in the project directory. Following is a sample Dockerfile to install ubuntu with postgres and apache

FROM ubuntu:rolling
  RUN apt update 
  RUN apt install -y vim python3-pip apache2 libapache2-mod-wsgi-py3 postgresql postgresql-contrib postgresql-server-dev-9.6 openssh-server sudo curl iproute
  RUN pip3 install --upgrade pip
  RUN pip3 install Django django-mathfilters lxml psycopg2-binary requests
  ADD install.sh /
  ENTRYPOINT ["/bin/bash", "-x", "install.sh", "arg1"]