Skip to content

Instantly share code, notes, and snippets.

@GKephart
Created March 12, 2019 23:25
Show Gist options
  • Save GKephart/d7f5d9ae7702c0148fac0fb274e2f63a to your computer and use it in GitHub Desktop.
Save GKephart/d7f5d9ae7702c0148fac0fb274e2f63a to your computer and use it in GitHub Desktop.

Important terms

  • URLs
  • IP addresses
  • Localhost VS. public IP addresses/web hosting
  • Domain names attach to public IPs

Ports:

  • 80 - is the default port for http://
  • 443 - default port for https://
  • 22 - default port for ssh 7822
  • 3306: for mysql
  • 2375/2376 - docker API

Protocols

(HTTP), subdomains (www)

Docker

Tool designed to create, deploy and run applications using containers and images

  • Better resource usage
  • Images are a fraction of a normal Virtual Machine (VM)
  • A slice of a computer
  • Containers run only what's in that slice
  • Good for Continuous Integration/Continuous Delivery (CI/CD)
  • Enables an easy way to host development environments and deploy your app
    • Dev, staging/QA (Quality Assurance), production
    • Related: Google Cloud Platform, Kubernetes, Amazon Web Services (AWS), Docker Swarm
  • "The Cloud": a physical computer, but somewhere else

Images

Images are the blue prints for containers

  1. Write up a Dockerfile
  2. Describes the kind of computer slice you want to use
  3. Describes what to install on that computer slice
  4. Lists other set up
  5. Use the Dockerfile to build an image
  • Images can be built on other images
  • Creates a rubber stamp for your containers
  • Is not a running computer
  • Use your image to spin up any number of containers
  • Running a container from an image uses the image's Dockerfile to spin up a mini computer
  • Meant to be ephemeral/short-lived
  • Easy to take up and down
  • Can be SSH'd into
  • Can run an entire application
  • Container orchestration

How to create an Image

Build the image with your DockerHub username: docker image build -t <YOUR_USERNAME>/pwp .

  • -t allows us to give the image our own name
  • . refers to where you want to create the image from

Check for the image:

docker image ls

Create a new container from the image:

docker container run --rm --name pwp -p 80:80 -d <YOUR_USERNAME>/pwp

  • --rm means to delete the container when it stops running (default is to be manually removed) *--name is optional but highly reccommended. Naming a container lets you reference it in commands by name instead of container id.
  • -p 80:80 means to publish Docker's port 80 to your local machine's port 80 (port 80 is the default port for http)
  • -d means to run in detach mode, or in other words in the background of your terminal

Check for the running container

docker container ls vs docker ps * I prefer docker container ls

USEFUL DOCKER COMMANDS

delete a container by either its name or containerId docker container rm -f name||id

Rename a docker image

docker image tag username/image-name

  • username must be your valid dockerhub username or you will not be able to push to dockerhub

Run a command on a running container

docker container exec command

  • exec stands for execute command can be any valid unix command as long as the right arguements are used.

gain shell access to a container

docker container exec –it bash || /bin/sh

  • -i stands for interactive
  • -t Allocate a pseudo-TT TLDR a terminal
  • bash || /bin/sh bash is not installed in all containers. in case bash is not installed use bin/sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment