git clone https://github.com/BretFisher/udemy-docker-mastery.git
curl -sSL https://get.docker.com/ | sh
-
docker pull- pull an image down from docker hub -
docker image ls- list all downloaded images -
docker version- check version -
docker info- show details about docker on the system -
docker <command>anddocker <command> <subcommand> -
docker container top- process list in the container -
docker container inspect- details of container config -
docker container stats- performance status of container -
Use the
--rmflag withdocker container runto have the container automatically closed -
docker container run -p- exposes port -
docker contianer port <contianer>- check which ports a contianer is usingdocker container run --publish 80:80 --detach nginx- run headlessdocker container stop 5791- stop containerdocker contianer ls- only shows running instancesdocker container ls -a- shows all intances
docker container logs 4dd8 - show logs
docker container top 4dd8c - see top running processes
docker container rm 4dd 579 624 - cleanup multiple contianers
docker container rm -f 4dd - force cleanup of running containers
docker rm $(docker ps -qa --no-trunc --filter "status=exited")- Cleanup all exited containers
docker run --name nginx --publish 80:80 -d nginxdocker run --name httpd --publish 8080:80 -d httpddocker run --name mysql --publish 3306:3306 --env MYSQL_RANDOM_ROOT_PASSWORD=yes -d mysqldocker psdocker logs mysqldocker container stop mysql httpd nginxdocker container rm mysql httpd nginxdocker container ls -a
docker contianer run -it- start new container interactivelydocker container exec -it- run additional command in existing container
docker network ls- list docker networksdocker network inspect <network>- inspect networkdocker network create --driver- attach a new network to containerdocker network disconnect <network>- deatch a network from computer- Containers on the same network are able to talk to each other using their names (DNS, NOT IP addresses)
**
docker container exec -it nginx ping new_nginx
docker container run -it --rm ubuntu:14.04**apt-get update && apt-get install -y curl**curl version-> 7.35docker container run -it --rm centos:7**curl version-> 7.29
docker network create dudedocker container run -d --net dude --net-alias search elasticsearch:2docker container lsdocker container run --rm --net dude alpine nslookup searchdocker container run --rm --net dude centos curl -s search:9200docker container rm -f jovial_northcutt zealous_panini
- Each of the layers get their own unique SHA value
- Layers can be OS, install commands, environment variables, system changes, etc
- Bundles of layers add up to make an image
docker image inspect nginx- returns back metadata about the imagedocker history mysql:latest- shows the history of all the layers within an image
- Tags are pointers to specific image commits
docker image tag nginx fuzzylimes/nginx- tag existing image with a new tagdocker image tag fuzzylimes/nginx fuzzylimes/nginx:testing- tag same image with a different (specific) tag namelatesttag is default. Used to represent the most recent and stable version
docker login- Login to DockerHubcat .docker/config.json- view filedocker logout- Delete login keydocker image push fuzzylimes/nginx:testing- push image file to Docker Hub- If using a private repo, create repo first before pushing
docker image build -t customnginx .- build image from dockerfile with tag in the specified directoryFROM- Defines the image to be used as the baseRUN- Runs a command (bash) inside the containerWORKDIR- Correct way of setting the working directory in a container (i.e. same ascding to path)COPY- Copy file into WORKDIR path
docker image build -t node-assignment-1 .docker container run -p 80:3000 --rm node-assignment-1:latestdocker image rm fuzzylimes/node-assignment-1docker container run -p 80:3000 --rm fuzzylimes/node-assignment-1:latest
# Instructions from the app developer
# - you should use the 'node' official image, with the alpine 6.x branch
FROM node:6-alpine
# - this app listens on port 3000, but the container should launch on port 80
# so it will respond to http://localhost:80 on your computer
EXPOSE 3000
# - then it should use alpine package manager to install tini: 'apk add --update tini'
RUN apk add --update tini \
# - then it should create directory /usr/src/app for app files with 'mkdir -p /usr/src/app'
&& mkdir -p /usr/src/app
WORKDIR /usr/src/app
# - Node uses a "package manager", so it needs to copy in package.json file
COPY package.json package.json
# - then it needs to run 'npm install' to install dependencies from that file
RUN npm install \
# - to keep it clean and small, run 'npm cache clean --force' after above
&& npm cache clean --force
# - then it needs to copy in all files from current directory
COPY . .
# - then it needs to start container with command '/sbin/tini -- node ./bin/www'
CMD ["/sbin/tini", "--", "node", "./bin/www"]
# - in the end you should be using FROM, RUN, WORKDIR, COPY, EXPOSE, and CMD commands- Data can be saved outside of the container using volumes
- Some images will do this automatically (like mysql)
docker volume ls- view the list of created volumes- To create a named volume, use the -v parmaeter:
docker container run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=True -v mysql-db:/var/lib/mysql mysql - Can also create volumes using the
docker volume createcommand. Only needed for specifying driver related stuff.
- Maps a host file or directory to a container file or directory
- Can't be specified in Dockerfile, must be done with
container run ...run -v /Users/name/stuff:/path/container
docker container run -d --name psql -v psql:/var/lib/postgresql/data postgres:9.6.1docker container stop psqldocker container run -d --name psql2 -v psql:/var/lib/postgresql/data postgres:9.6.2docker container logs psql2
cd udemy-docker-mastery/bindmount-sample-1/docker run -p 80:4000 -v $(pwd):/site bretfisher/jekyll-serve
- Configures the relationships between containers
- saves our docker container run settings in yml file
- create one-liner environment startups
- Made of two things: ** YML file ** cli tool docker-compose
- docker-compose.yml is defail, but can use any name with
docker-compose -f
-
version: always use at least 2, defaults to 1 (3.1 current)
-
services: containers. Same as docker run ** servicename: a friendly name, DNS name inside the network ** image: (Optional) ** command: (Optional) replace the defualt CMD specified by the image ** environement: (Optional) same as -e in docker run ** volumes: (Optional) same as -v in docker run
-
volumes: (Optional) same as docker volume create
-
network: (Optional) same as docker network create
version: '2'
# same as
# docker run -p 80:4000 -v $(pwd):/site bretfisher/jekyll-serve
services:
jekyll:
image: bretfisher/jekyll-serve
volumes:
- .:/site
ports:
- '80:4000'version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
volumes:
- ./wordpress-data:/var/www/html
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- ./mysql-data:/var/lib/mysqlcd /udemy-docker-mastery/compose-sample-2
version: '3'
services:
proxy:
image: nginx:1.11 # using version 1.11.x
ports:
- '80:80' # expose 80 on host and sent to 80 in container
volumes:
# can set a file to be read only (ro) inside container
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
web:
image: httpddocker-compose up- streaming logsdocker-compose up -d- run in backgrounddocker-compose logs- get logs from compose (same as those streamed)docker-compose ps- list containers run by docker-composedocker-compose down- stop and cleanup
version: '2'
services:
drupal:
image: drupal
ports:
- '8080:80'
volumes:
- drupal-modules:/var/www/html/modules
- drupal-profiles:/var/www/html/profiles
- drupal-themes:/var/www/html/themes
- drupal-sites:/var/www/html/sites
postgres:
image: postgres
environment:
POSTGRES_PASSWORD: example
volumes:
drupal-modules:
drupal-profiles:
drupal-themes:
drupal-sites:docker-compose down -v: take down and remove volumes
- Will build the first time when
docker-compose upis run - Can run
docker-compose buildto rebuild
version: '2'
services:
drupal:
image: custom-drupal
build: .
ports:
- '8080:80'
volumes:
- drupal-modules:/var/www/html/modules
- drupal-profiles:/var/www/html/profiles
- drupal-themes:/var/www/html/themes
- drupal-sites:/var/www/html/sites
postgres:
image: postgres
environment:
POSTGRES_PASSWORD:
volumes:
- drupal-data:/var/lib/postgresql/data
volumes:
drupal-modules:
drupal-profiles:
drupal-themes:
drupal-sites:
drupal-data:FROM drupal:8.2
RUN apt-get update && apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /var/www/html/themes
RUN git clone --branch 8.x-3.x --single-branch --depth 1 https://git.drupal.org/project/bootstrap.git \
&& chown -R www-data:www-data bootstrap
WORKDIR /var/www/html