Code Monkey home page Code Monkey logo

docker's Introduction

Docker

Container - Container is a running environment for IMAGE

  • virtual file system
  • port binded: talk to application running inside of container
  • application image: postgres, redis mongo, nginx, python (etc)

Main Docker CLI commands

  1. how to search a docker image in hub.docker.com from CLI
  • docker search httpd
  1. Download a docker image from hub.docker.com
  • docker image pull <image_name>:<image_version/tag>
  1. List out docker images from your local system
  • docker images or
  • docker image ls
  1. Create/run/start a docker container from image
  • docker run -d --name <container_Name> <image_name>:<image_version/tag>
  • d - run your container in back ground (detached)
  1. Expose your application to host server
  • docker run -d -p <host_port>:<container_port> --name <container_Name> <image_name>:<Image_version/tag>
  • docker run -d -p 8080:80 -p 3000:80 --name starwars httpd:2.3

if the above command isn't working use the following

  • docker run -d --restart unless-stopped -p <host_port>:<container_port> --name <container_Name> <image_name>:<Image_version/tag>
  • EXAMPLE: docker run -d --name httpd_server -p 8080:80 httpd:2.2
  1. List out running containers
  • docker ps
  1. List out all docker container (running, stpooed, terminated, etc...)
  • docker ps -a
  1. run a OS based container which interactive mode (nothing but login to container after it is up and running)
  • docker run -i -t --name centos_server centos:latest
  • i - interactive
  • t - Terminal
  1. Stop a container
  • docker stop <container_id>
  1. Start a container which is in stopped or exit state
  • docker start <container_id>
  1. Remove a container (Can not remove a running container)
  • docker rm <container_id>
  1. login to a docker container
  • docker exec -it <container_Name> /bin/bash
  1. Pull only Container Ids
  • docker ps -aq
  1. Delete multiple containers
  • docker rm $(docker ps -aq)
  • docker rmi $(docker images -aq)
  1. Format Container
  • docker ps --format="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"
  1. Run Dockerfile to create image (Dockerfile - Contains a series of steps that define how your image is build.)
  • docker build . -t httpd:latest
  • "t" tag
  1. Docker run
  • docker run -p 8080:8080 httpd:latest
  1. Docker Volumes (allow sharing of data between files, folders & containers)
  • (example to share files between local and container run) docker run -d --name website -v $(pwd):/usr/share/nginx/html:ro -p 8080:80 nginx:latest
  • "ro" read only. If we want to write then we need to remove "ro"
  • (example to share files between containers)
  • docker run -d --name website-copy --volumes-from website -p 8081:80 nginx
  1. Docker compose up & down commands
  • docker-compose -f docker-compose.yaml up -d
  • docker-compose -f docker-compose.yaml down
  1. Docker network
  • docker network ls
  • docker network create <network_name>

docker's People

Contributors

samishken avatar

Watchers

James Cloos avatar  avatar

Forkers

jorgia111

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.