Docker - ayaohsu/Personal-Resources GitHub Wiki
Container: A way to package application with all the necessary dependencies and configuration
- Self-Contained
- Portability
Public Repo (docker hub): This contains the official and unofficial images of applications/tools you can use
Problems that containers solve:
- Developers need to install apps and set up configurations themselves
Docker contains layers of components of an image. When you upgrade a version, only different layers are downloaded.
Image is the actual package. It is the app + services + scripts + config. It is an artifact that can be moved around.
Container is the actual process/environment when the application starts. When it starts, a container environment is created.
Basically it is running vs not-running.
They are both virtualization tools.
Containers virtualize the application layer, while VM virtualizes the kernal layer.
$ docker pull redis
$ docker images
$ docker run redis
$ docker ps
$ docker stop 862386c58c1d
$ docker ps -a (all container even if exited)
$ docker run redis:4.0 (pull the version and run)
The host (PC or laptop) has multiple ports available to assign to containers. Each container has to have its own binding host port. However, a 'container port' is the port managed on the container side. This can be the same for different containers.
docker run -p6000:6379 Host port: 6000; Container port: 6379
$ docker exec -it /bb/bin
- env
- exit
Docker can integrate with the following steps:
- Development
- Continuous Integration
- Deployment
$ docker network ls
$ docker network create mongo-network
$ docker run -d \
-p 27017:27017 -e MONGO_INITDO_ROOT_USERNAME=admin
-e MONGO_INITDB_ROOT_PASSWORD=password
--name mongodb
--net mongo-network
mongo
Start multiple services in .yaml
file
$ docker-compose -f mongo.yaml up
$ docker-compose -f mongo.yaml down
A blueprint for building images
WORKDIR -> this will be in the virtual environment, not the host
COPY -> executes on the HOST machine so you can copy from host to docker
CMD -> run inside the container (["node", "server.js"]). This is the entry point
To build an image on our own:
$ docker build -t my-app:1.0 .
$ docker rm (remove a container)
$ docker rmi (remove an image)