Skip to content

Instantly share code, notes, and snippets.

@ilhnctn
Last active October 30, 2018 07:59
Show Gist options
  • Save ilhnctn/43d3678f6128dbff1e838c923337e1d0 to your computer and use it in GitHub Desktop.
Save ilhnctn/43d3678f6128dbff1e838c923337e1d0 to your computer and use it in GitHub Desktop.

Docker

Agenda

  • What is docker?
  • Docker vocabulary & commands
  • Compose & usage
  • Demo (dockerise Omnishop)
  • Docker for Dev & CI/CD (next session ?)
  • Kubernetes/AWS (next session)

What is docker?

Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.

Image: An image is an executable package that includes everything needed to run an application--the code, a runtime, libraries, environment variables, and configuration files.

Container: A container is a runtime instance of an image--what the image becomes in memory when executed (that is, an image with state, or a user process) (If image is a class, container is its object)

Docker Vocabulary, Concepts & Commands

Dockerfile: Image definition file

  • Format (FROM, ENV, RUN, CMD, ENTRYPOINT, comments, etc)
  • Volume (persistance)
  • Networking (default driver: bridge)

Commands

➜  docker attach      # -- Attach local standard input, output, and error streams to a running container
➜  docker build       # -- Build an image from a Dockerfile
➜  docker checkpoint  # -- Manage checkpoints
➜  docker commit      # -- Create a new image from a container's changes
➜  docker config      # -- Manage Docker configs
➜  docker container   # -- Manage containers
➜  docker cp          # -- Copy files/folders between a container and the local filesystem
➜  docker create      # -- Create a new container
➜  docker daemon      # -- Enable daemon mode
➜  docker deploy      # -- Deploy a new stack or update an existing stack
➜  docker diff        # -- Inspect changes to files or directories on a container's filesystem
➜  docker events      # -- Get real time events from the server
➜  docker exec        # -- Run a command in a running container
➜  docker export      # -- Export a container's filesystem as a tar archive
➜  docker help        # -- Show help for a command
➜  docker history     # -- Show the history of an image
➜  docker image       # -- Manage images
➜  docker images      # -- List images
➜  docker import      # -- Import the contents from a tarball to create a filesystem image
➜  docker info        # -- Display system-wide information
➜  docker inspect     # -- Return low-level information on Docker objects
➜  docker kill        # -- Kill one or more running containers
➜  docker load        # -- Load an image from a tar archive or STDIN
➜  docker login       # -- Log in to a Docker registry
➜  docker logout      # -- Log out from a Docker registry
➜  docker logs        # -- Fetch the logs of a container
➜  docker network     # -- Manage networks
➜  docker node        # -- Manage Swarm nodes
➜  docker pause       # -- Pause all processes within one or more containers
➜  docker plugin      # -- Manage plugins
➜  docker port        # -- List port mappings or a specific mapping for the container
➜  docker ps          # -- List containers
➜  docker pull        # -- Pull an image or a repository from a registry
➜  docker push        # -- Push an image or a repository to a registry
➜  docker rename      # -- Rename a container
➜  docker restart     # -- Restart one or more containers
➜  docker rm          # -- Remove one or more containers
➜  docker rmi         # -- Remove one or more images
➜  docker run         # -- Run a command in a new container
➜  docker save        # -- Save one or more images to a tar archive (streamed to STDOUT by default)
➜  docker search      # -- Search the Docker Hub for images
➜  docker secret      # -- Manage Docker secrets
➜  docker service     # -- Manage services
➜  docker stack       # -- Manage Docker stacks
➜  docker start       # -- Start one or more stopped containers
➜  docker stats       # -- Display a live stream of container(s) resource usage statistics
➜  docker stop        # -- Stop one or more running containers
➜  docker swarm       # -- Manage Swarm
➜  docker system      # -- Manage Docker
➜  docker tag         # -- Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
➜  docker top         # -- Display the running processes of a container
➜  docker trust       # -- Manage trust on Docker images
➜  docker unpause     # -- Unpause all processes within one or more containers
➜  docker update      # -- Update configuration of one or more containers
➜  docker version     # -- Show the Docker version information
➜  docker volume      # -- Manage volumes
➜  docker wait        # -- Block until one or more containers stop, then print their exit codes

and more

Docker-compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Vocabulary, Commands and Concepts

  • Scaling (docker-compose scale shop=3 omnipro=5 celery=1)
  • Environments
  • Volumes
  • Networks

Commands

➜  docker-compose build    # -- Build or rebuild services
➜  docker-compose bundle   # -- Generate a Docker bundle from the Compose file
➜  docker-compose config   # -- Validate and view the Compose file
➜  docker-compose create   # -- Create services
➜  docker-compose down     # -- Stop and remove containers, networks, images, and volumes
➜  docker-compose events   # -- Receive real time events from containers
➜  docker-compose exec     # -- Execute a command in a running container
➜  docker-compose help     # -- Get help on a command
➜  docker-compose images   # -- List images
➜  docker-compose kill     # -- Kill containers
➜  docker-compose logs     # -- View output from containers
➜  docker-compose pause    # -- Pause services
➜  docker-compose port     # -- Print the public port for a port binding
➜  docker-compose ps       # -- List containers
➜  docker-compose pull     # -- Pull service images
➜  docker-compose push     # -- Push service images
➜  docker-compose restart  # -- Restart services
➜  docker-compose rm       # -- Remove stopped containers
➜  docker-compose run      # -- Run a one-off command
➜  docker-compose scale    # -- Set number of containers for a service
➜  docker-compose start    # -- Start services
➜  docker-compose stop     # -- Stop services
➜  docker-compose top      # -- Display the running processes
➜  docker-compose unpause  # -- Unpause services
➜  docker-compose up       # -- Create and start containers
➜  docker-compose version  # -- Show the Docker-Compose version information

Sample Usage

➜  docker-compose up --build (or only `docker-compose build)
➜  docker-compose ps
➜  docker-compose stop
➜  docker-compose run shop pip uninstall django-extensions
➜  docker-compose run shop python manage.py shell_plus --settings=shomnipro.settings

Welcome To the Wild wild West

So, let's dockerize our basic shop project and see what happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment