Docker Basics - p-patel/software-engineer-knowledge-base GitHub Wiki

Learn Docker in 12 Minutes

https://www.youtube.com/watch?v=YFl2mCHdv24

  • A container is a running instance of an image (a template of an environment)
  • Image contains: OS, software, application code
  • Dockerfile defines an image (contains the steps required to create that image)
  • Dockerfile -> (build) -> Image -> (run) -> Container

Getting Started

  • Install Docker for Win/Mac
  • Create /src directory containing web app code
  • Create Dockerfile in the directory that contains the /src directory
  • Find suitable image on http://hub.docker.com (image page contains Dockerfile configuration details)
FROM php:7.0-apache
COPY src/ /var/var/html
EXPOSE 80

copies php web app to image and exposes port 80 in the image

docker build -t hello-world .

builds an image using the Dockerfile in the current directory, naming the image hello-world

docker run -p 80:80 hello-world

runs the docker image hello-world, forwards port 80 on the host to port 80 on the container

docker run -p 80:80 -v /Users/jake/Desktop/docker/src/:/var/www/html/ hello-world

mount a volumne on the container that maps to a directory on the host machine (e.g. for app code during development). REMEMBER: this requires the image to be rebuilt before deployment for it to contain the latest app changes!

The life of a container is tied to directly a single process!

Example Repo

https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp