Skip to content

Instantly share code, notes, and snippets.

@awssimplified
Created July 26, 2020 15:03
Show Gist options
  • Save awssimplified/75c965a569c67d9ad516ad04de8a095f to your computer and use it in GitHub Desktop.
Save awssimplified/75c965a569c67d9ad516ad04de8a095f to your computer and use it in GitHub Desktop.
Docker Notes
---
docker daemon
REST Api to interact with it
CLI to interact with it uses the REST APIs
your docker daemon can run on a totally different machine and you can issue commands to it from your local
'dockerd' = daemon
'docker' = using the api
Images
---
r/o with instructions for creating container
an image can be based on another image
instructions create layers in the image
images can be parent child relationships
Containers
---
runnable instance of image
docker run -i -t ubuntu /bin/bash
^ run ubuntu image in a container and run the /bin/bash
Services
---
allow you to scale across multiple daemons (possibly on other machines) <-- swarm
You can have a swarm which is a grouping of containers. This grouping is orchestrated by a single daemon that manages the swarm.
By default, the service is load-balanced across all worker nodes
dependencies, app config, etc bundled into image. Quick redeploys using new images.
Phases - build, ship, run
Solves the "Works on My Machine" phenomenon
Syntax
---
FROM = base image
FROM node:12.16.3
WORKDIR
WORKDIR /code
^ creates dir and uses as working
ENV
ENV PORT 80
^ set environment variable
COPY
COPY package.json /code/package.json
^ copy to dir
RUN
RUN npm install
CMD
CMD ["node", "src/server.js"]
^ tells docker run command and target
.dockerignore -> tell docker to not copy over these files/directories
Building
---
docker build --tag hello-world .
docker images
^ see installed images
Running
---
docker run [image]
^ you can specify a ton of things like memor, cpu, io, network
docker ps -a shows you non running images
docker ps shows you running images
docker rm [gets rid of images]
if you dont specify a name, docker will you you some wacky one
docker run -p 8080:80 --name hello -d hello-world
-p maps local port 8080 to container port 80
-d allows for detached mode
*** docker system prune *** to get rid of old non-running images
docker stop
docker logs -f [container]
docker hub for private images
can connect to docker hub image to get rebuilt on git commit
docker tag hello-world dg/hello-world
if you want to push to hub, your images namespace must match the namespace as hub
Docker Compose
---
allows you to specify yaml files that define the run specification (can be 1 or more services)
docker-compose up -d
up means run but for all services in the compose
Open Questions
---
1) Where do we specify the resources of the container? --> Run Command
2) Branches of images? --> Done by Tagging
Notes
---
Good tutorial - https://www.youtube.com/watch?v=iqqDU2crIEQ
Docker Notes
---
docker daemon
REST Api to interact with it
CLI to interact with it uses the REST APIs
your docker daemon can run on a totally different machine and you can issue commands to it from your local
'dockerd' = daemon
'docker' = using the api
Images
---
r/o with instructions for creating container
an image can be based on another image
instructions create layers in the image
images can be parent child relationships
Containers
---
runnable instance of image
docker run -i -t ubuntu /bin/bash
^ run ubuntu image in a container and run the /bin/bash
Services
---
allow you to scale across multiple daemons (possibly on other machines) <-- swarm
You can have a swarm which is a grouping of containers. This grouping is orchestrated by a single daemon that manages the swarm.
By default, the service is load-balanced across all worker nodes
dependencies, app config, etc bundled into image. Quick redeploys using new images.
Phases - build, ship, run
Solves the "Works on My Machine" phenomenon
Syntax
---
FROM = base image
FROM node:12.16.3
WORKDIR
WORKDIR /code
^ creates dir and uses as working
ENV
ENV PORT 80
^ set environment variable
COPY
COPY package.json /code/package.json
^ copy to dir
RUN
RUN npm install
CMD
CMD ["node", "src/server.js"]
^ tells docker run command and target
.dockerignore -> tell docker to not copy over these files/directories
Building
---
docker build --tag hello-world .
docker images
^ see installed images
Running
---
docker run [image]
^ you can specify a ton of things like memor, cpu, io, network
docker ps -a shows you non running images
docker ps shows you running images
docker rm [gets rid of images]
if you dont specify a name, docker will you you some wacky one
docker run -p 8080:80 --name hello -d hello-world
-p maps local port 8080 to container port 80
-d allows for detached mode
*** docker system prune *** to get rid of old non-running images
docker stop
docker logs -f [container]
docker hub for private images
can connect to docker hub image to get rebuilt on git commit
docker tag hello-world dg/hello-world
if you want to push to hub, your images namespace must match the namespace as hub
Docker Compose
---
allows you to specify yaml files that define the run specification (can be 1 or more services)
docker-compose up -d
up means run but for all services in the compose
Open Questions
---
1) Where do we specify the resources of the container? --> Run Command
2) Branches of images? --> Done by Tagging
Notes
---
Good tutorial - https://www.youtube.com/watch?v=iqqDU2crIEQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment