-
Virtual machines have their own individual OS and also use more cpu, ram, storage.
-
Containers are in an isolated of OS environment, they can share the same OS. Use less cpu, ram, storage.
-
Images contain the setup code, environment only.
-
Containers provide runtime functionality, they are responsible for running.
-
docker run image → also pulls the image if it doesn't exist locally.
-
when we run
docker run
some interactive shell of the software/image is running inside the container but we might not have access to it because the environment is isolated and the interactive shell exposed by the container is not by default exposed to us. Use docker -it run node to do that. -
Every time we run docker run a new container instance spins up
docker pull nginx # Pulls an image from docker hub docker run node # Runs a container containing image docker ps -a # shows all containers(processes) (running and exited) docker ps # shows only running processes docker run -it node # expose an iteractive session from inside the container to host machine docker build . # builds an image based on specified path docker stop container_name/id docker run -p 3000:80 container_name # publish localhost:container_expose_port
-
Dockerfile is instructions to docker engine on how to build an image it doesn't run the container
-
Images are read-only type so every time we make a small change to code we have to rebuild the image. The rebuilding is done by taking a snapshot and comparing(layer based). When you rebuild an image only the changes are updated
-
Images are closed templates.
-
Containers are just an extra thin layer on top of the image
-
Image contains everything. You can run multiple containers based on images.
-
A container does not copy the code from image, it just creates and extra layer on top of image and allocate resources, memory to run app and so on.
-
Container is an isolated unite of software which is based on an image. a running instance of that image.
docker start container_name # running existing containers -- we're not able to interact with it from local machine but it's started and running # start runs container in background and run in foreground # run has attach mode as default and start has detached mode as default docker start -a container_name # start in attached mode/ run default # run in detached mode docker run -p 8000:80 -d container_id docker attach container_name # attach to container again docker logs container_name # show the log output in detached mode docker logs -f container_name # keep on listening / attached mode again
-
The container needs to be removed first and then only you can remove image
docker ps -a docker rm container_name1 container_name2 .... docker images docker rmi image_id1 image_id2 .... docker image prune -a # removes all unused images by containers docker run -p 3000:80 -d --rm container_name # remove the container when it stops # Expose 80 should be same as the port nodeapp is running on
-
Multiple containers using same image share code hence images are read only.
docker image inspect image_id
docker build -t rutwik/posts . # build an image based on cur-dir and tag it with name rutwik/posts docker run rutwik/posts docker run -it rutwik/posts sh # start a shell in dir instead running npm start docker exec -it container_id sh # execute a given command in a running container docker logs container_id # Print out logs from the given container
# REMOVE ALL CONTAINERS AND IMAGES AND DELETE VOLUMES docker rm -vf $(docker ps -a -q) docker rmi -f $(docker images -a -q)
-
Copy code from local directory to already running folder
docker cp folder_name/. name_of_container:/path_of_folder_to_copy # . = everything, path_of_folder is created if it doesn't exist. docker cp name_of_container:/path_of_folder_to_copy # this command will copy from docker container to local dir
-
Add image to docker hub(remote)
docker login # create image repository on docker hub just like git. # tag or create a new image locally based on the docker hub image name. docker tag local:latest docker_hub/hello-world docker push docker_hub/hello-world # get image locally docker pull image_name:tag
-
Volumes and data
- Types of data:
- Application (code+environment)
- Temporary app data since it's read write it's stored in containers not images.
- Permanent App data(Volumes)
- Volumes are folders on your host machine hard drive, which are mounted(mapped) into containers
docker run -d -p 3000:80 --rm --name feedback-app feedback-node:volumes
- Types of data:
docker-notes's Introduction
docker-notes's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.