Common Docker Commands

Here are some common Docker commands.

1. Search the Docker repository (like Docker Hub) for Docker images.

docker search IMAGE

2. Pull an image from the Docker repository.

docker pull IMAGE

3. Print the image change history.

docker history IMAGE

4. List all images on the host system.

docker images

5. Create and run a container. A container is an instance of an image.

docker run --name CONTAINER IMAGE

6. Create and run an interactive container.

docker run -it --name CONTAINER IMAGE

7. Create and run a container, and remove container on exit.

docker run --rm --name CONTAINER IMAGE

8. Create and run a container with a mounted volume from the host.

docker run -d --name CONTAINER -v HOST_DIR:CONTAINER_DIR IMAGE

9. Create and run a container as a daemon.

docker run -d --name CONTAINER IMAGE

10. Attach to a running container.

docker attach CONTAINER

11. Tail the container console.

docker logs -f CONTAINER

12. Stop, start or restart a container.


docker stop CONTAINER

docker start CONTAINER
docker restart CONTAINER

13. List running containers.

docker ps

14. List all containers.

docker ps -a

15. List container ports.

docker port CONTAINER

16. Print low-level information on a container or image.

docker inspect CONTAINER|IMAGE

17. Delete a container, stop it first if running.

docker rm -f CONTAINER

18. Delete an image.

docker rmi IMAGE

19. Create a new image based on a Dockerfile.

docker build -t IMAGE

20. Commit container changes made using an interactive shell into a new image.

docker commit CONTAINER IMAGE:TAG

21. Push an image to the Docker repository.

docker push IMAGE:TAG

22. Display Docker system information.

docker info

23. Display running processes inside the container.

docker top CONTAINER

24. Display the container’s resource usage.

docker stats CONTAINER

25. Link two containers, a web application connecting to a database, using a secure tunnel.


docker run -d --name DB_CONTAINER DB_IMAGE
docker run -d -P --name WEB_CONTAINER --link DB_CONTAINER:DB_ALIAS WEB_IMAGE

Bonus: Install Docker on Red Hat or CentOS.

yum install docker-io; service docker start; chkconfig docker on

Oracle Cheat Sheet

1. Ping Oracle.

tnsping SID

2. Get the SID.

SHOW PARAMETER instance_name;

3. JDBC driver.

oracle.jdbc.OracleDriver

4. JDBC driver URL pattern.

jdbc:oracle:thin:@HOST:PORT:SID

5. Date greater than clause.

date_col > TO_DATE('2015-01-01','yyyy-MM-dd')

 


Sample ElasticSearch Queries

1. Query all.

GET http://localhost:9200/index/type/_search

2. Query by single value, using a query string.

GET http://localhost:9200/index/type/_search?q=firstName:John

3. Query by single term, using request body.

GET http://localhost:9200/index/type/_search
    {
        "query": {
            "term": { "firstName" : "John" }
        }
    }

4. Paging query.

GET http://localhost:9200/index/type/_search
    {
        "from" : 0,
        "size" : 10,
        "query" : {
            "term" : { "firstName" : "John" }
        }
    }

5. Pre-filter.

 GET http://localhost:9200/index/type/_search
    {
        "query": {
            "filtered": {
                "filter": {
                    "term": { "firstName" : "John" }
                }
            }
        }
    }

6. Pre-filters.

GET http://localhost:9200/index/type/_search
    {
        "query": {
            "filtered": {
                "filter": {
                    "and": {
                        "filters": [ {
                            "term": { "firstName": "John", "country": "US" }
                        } ]
                    }
                }
            }
        }
    }

7. Pre-filter terms.

GET http://localhost:9200/index/type/_search
    {
        "query": {
            "filtered": {
                "filter": {
                    "and": {
                        "filters": [ {
                            "term": { "firstName": "John" }
                        }, {
                            "terms": { "country": [ "US", "CA" ] }
                        } ]

8. Missing email filter.

GET http://localhost:9200/index/type/_search

    {
        "query": {
            "filtered": {
                "filter": {
                    "missing": { "field" : "emailAddress" }
                }
            }
        }
    }

9. Pre-filtered query.

GET http://localhost:9200/index/type/_search
    {
        "query": {
            "filtered": {
                "query": {
                    "term": { "firstName": "John" }
                },
                "filter": {
                    "term": { "country": "US" }
                }
            }
        }
    }

10. Nested filter.

GET http://localhost:9200/index/type/_search

    {
        "query": {
            "filtered": {
                "filter": {
                    "nested": {
                        "path": "person",
                        "filter": {
                            "term": { "person.country": "US" }
                        }
                    }
                }
            }
        }
    }

11. Nested and non-nested filter.

{
        "query": {
            "filtered": {
                "filter": {
                    "and": {
                        "filters": [ {
                            "term": { "firstName": "John" }
                        }, {
                            "nested": {
                                "path": "person",
                                "filter": {
                                    "term": { "person.country": "US" }
                                }
                            }
                        } ]
                    }
                }
            }
        }
    }