Pages

Friday, February 17, 2017

All about Docker Docker Cheet Sheet by Sameera Dissanayaka

Docker Cheat Sheet

Docker Cheat sheet
By Sameera Madushan Dissanayaka

Build docker image
docker build -t Sameera/Dissanayaka .

Run Docker image
Demon mode
docker run -dt -p 80:80 docker_image_name

Intaractive mode

docker run -id -p 80:80 docker_image_name bash
when you exit docker container distroyed

Check docker images

docker images

Check running docker containers
docker ps

Checke stopped docker container and running docker containers

docker ps -a

Stop running docker container
(1234 docker container id or docker image id)
docker stop 1234

Restart stopped container 

docker restart 1234

Remove docker container

docker rm 1234

Forced remove docker container

docker rm -f 1234

Remove docker image

docker rmi 1234

Identify host and container side of docker port allocation

docker run -dt -p 8081:80

8081 container
80 hostulk

Bulk remove container 

docker rm 1234 5678 1432

Bulk image remove

docker rmi 1234 5678 1432

Access the docker container

docker exec -it 1234 bash

Remove stopped docker container

docker rm $(docker ps -a -q)

Remove all the containers

docker rm -f $(docker ps -a -q)

Periodcally remove stopped containers

Create cron job to remove all stopped containers

*/30 * * * * docker rm $(docker ps -a -q)  >> /var/log/docker_removed.log

Inspect the docker container

docker inspect 1234

Check IPAddress of container

docker inspect 1234 |grep IPAddress

Link docker container db container to container mywebcontainer

docker run -d -p 8081:80 --name sameera --link db -t mywebcontainer

Change docker image name container abc in to sam

docker tag abc sam

Shared container folder with host

docker run -dt -v /var/www/hostside:/var/www/containerside  name_of_image

Shared Container

docker run -d --volumes-from nameofcontainer -- db docker_image_name

To Be Continued ....

















How to get free SSL certificate

Get free ssl certificate on apache server on Debian

1. Go  to https://certbot.eff.org  and select OS type and web server

2.Ex:- Apache on Ubuntu 16.04 
Install sudo apt-get install python-letsencrypt-apache

3.Generate certificate and insert into apache 
letsencrypt --apache
4.Automate renewal
Let’s Encrypt Certificate last for 90 days so after 90 days it should be renew
Add cron job  letsencrypt renew


How to add free SSL cert to nginx on amazon aws AMI

First download certbot and change write permission
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto
./mention installed path /certbot-auto certonly
./mention installed path /certbot-auto certonly --standalone -d yourwebsite.com -d yourotherwebsitedomain
Certification is valid for 30 days
Test automatic renew using
./mention installed path /certbot-auto renew --dry-run
add cron job to execute relevent time
./mention installed path/certbot-auto renew --quiet